码迷,mamicode.com
首页 > Web开发 > 详细

静态化 - 伪静态技术(PHP正则表达式实现)

时间:2016-01-28 16:43:04      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

效果:
技术分享

 

代码:

<?php
// + —— —— —— —— —— —— ——  —— —— —— —— —— —— —— —— ——  —— —— —— —— —— —— 
// + 正则表达式,实现伪静态处理
// + url:http://localhost/forgestatic/index.php/news-class12-id43.html
// + —— —— —— —— —— —— ——  —— —— —— —— —— —— —— —— ——  —— —— —— —— —— —— 

//设置输出编码
header(‘Content-Type:text/html; charset=utf8‘);

//获取参数信息
//参数格式为:‘/news-class12-id43.html‘
$_urlParam = $_SERVER[‘PATH_INFO‘];

// 匹配模式
// 匹配后格式:
// Array
// (
//     [0] => /news-class12-id43.html
//     [1] => news
//     [2] => class12
//     [3] => class
//     [4] => 12
//     [5] => id43
//     [6] => id
//     [7] => 43
// )
$_pattern  = ‘#^/([a-z]+)-(([a-z]+)([0-9]+))-(([a-z]+)([0-9]+))\.html$#‘;

//接收数据参数
$_paramArr = array();

//匹配获取
if ( preg_match($_pattern, $_urlParam, $_paramArr) ) {
	//打印数据
	echo ‘<pre>‘;
	print_r($_paramArr);
	echo ‘</pre>‘;
} else {
	exit(‘参数格式异常!‘);
}

 

静态化 - 伪静态技术(PHP正则表达式实现)

标签:

原文地址:http://www.cnblogs.com/KTblog/p/5166392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!