静态化

效果:

代码:

<?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('参数格式异常!');
}
原文地址:https://www.cnblogs.com/KTblog/p/5166392.html