就一个PHP字符串替换问题,怎么问了几次都没人会啊?
页面中有多个类似这样的:thread?tid=161n6k2c8i
我要把所有替换成这种形式:thread/161n6k2c8i.html
httpd.ini规则都做好了,就差上面页面替换了?来个高手吧!急!!
我要把所有替换成这种形式:thread/161n6k2c8i.html
httpd.ini规则都做好了,就差上面页面替换了?来个高手吧!急!!
作者: wyuser9527 发布时间: 2011-06-09
PHP code
$s = 'thread?tid=161n6k2c8i'; $ar1 = explode('?',$s); $ar2 = explode('=',$ar1[1]); $s = $ar1[0].'/'.$ar2[1].'.html'; echo $s;
作者: T5500 发布时间: 2011-06-09
$str=str_replace("thread?tid=","http://localhost/thread/",$str); //我用这个已经能替换掉前面半截了就差在后面加上.html了
是不是要用这个方法:eregi()或者用别的。 怎么写?
是不是要用这个方法:eregi()或者用别的。 怎么写?
作者: wyuser9527 发布时间: 2011-06-09
$str=$str.'.html';
不就完事了?
不就完事了?
作者: PhpNewnew 发布时间: 2011-06-09
thread?tid=161n6k2c8i //页面有多个tid不一样的url
作者: wyuser9527 发布时间: 2011-06-09
PHP code
$s = 'thread?tid=161n6k2c8i'; function mkURL($s) { $ar1 = explode('?',$s); $ar2 = explode('=',$ar1[1]); return 'http://localhost/'.$ar1[0].'/'.$ar2[1].'.html'; } echo mkURL($s);
作者: T5500 发布时间: 2011-06-09
PHP code
$str="thread?tid=161n6k2c8i"; $str2="thread/161n6k2c8i.html"; function myReplace($str){ if(strpos($str,"thread?tid")===false){ return false; } else{ return str_replace("thread?tid=","thread/",$str).".html"; } } echo myReplace($str);
作者: adin283 发布时间: 2011-06-09