Home > php教程 > php手册 > PHP如何生成伪静态

PHP如何生成伪静态

WBOY
Release: 2016-06-13 10:34:26
Original
827 people have browsed it

很多虚拟主机不支持URL_rewrite

昨天也看到经典一朋友写了一个

感觉代码太多.

无事中研究了一下_SERVER.其实可以很简化的

拿http://www.xxx.com/xxx/test.php/article.123456.html来说事吧.

这样的格式来表示_GET
http://www.xxx.com/xxx/test.php/article.123456.html
http://www.xxx.com/xxx/test.php?article=123456

==================================
哪种格式更帅呢.
代码如下:
CODE: $path_info =$_SERVER["PATH_INFO"]; //取得PATH_INFO
/*用正则来匹配 "/article.123456.html"*/
if(eregi("^/[a-z]{1,16}.[0-9]{1,16}.html$",$path_info)) {
echo "OK";
$get_path=substr($path_info,1,-5);//处理造型:D 去掉"/",".html"
$arr_path=explode(.,$get_path);//处理成数组备用
//以下是打印出数组看看我们有没有搞错的哦.:cool:
foreach ($arr_path as $key=>$value){
echo $arr_path[.$key.]:.$value."
";
}
}else echo "NO";
结果如下

CODE: $arr_path[0]:article
$arr_path[1]:123456
直接当$_GET使用吧,呵呵.PHP生成伪静态就是这么简单

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template