PHP头条
热点:

求一段php正则轮换规则


求一段php正则替换规则
/e/tags/index.php?page=23&tagname=%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4&line=3&tempid=13

用preg_replace()把这样的替换成
/tag-%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4/23/

当page=0的时候替换成
/tag-%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4/ 分享到:
------解决方案--------------------
$str="/e/tags/index.php?page=0&tagname=%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4&line=3&tempid=13";
$s= preg_replace_callback(
     '#.+?page=(\d+)&tagname=([^&]+)&.+#',
     create_function(
            '$matches',
            'return "/tag-$matches[2]/". ($matches[1] ? $matches[1]."/" : "");'
        ),
$str
);
echo $s;

/tag-%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4/

www.phpzy.comtrue/phprm/10192.htmlTechArticle求一段php正则轮换规则 求一段php正则替换规则 /e/tags/index.php?page=23line=3tagname=%B9%D8%D3%DA%D3%D1%D2%EA%D5%E4%B9%F3%B5%C4%B8%F1%D1%D4tempid=13"; $s=preg_replace_callback( '#.+?page=(\d+)]+)nbsp;create_function( '$match...

相关文章

相关频道:

PHP之友评论

今天推荐