静态化 - 伪静态技术(PHP正则表达式实现)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了静态化 - 伪静态技术(PHP正则表达式实现)相关的知识,希望对你有一定的参考价值。
效果:
代码:
<?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正则表达式实现)的主要内容,如果未能解决你的问题,请参考以下文章
PHP 伪静态规则写法RewriteRule-htaccess详细语法使用