php正则替换 保留数字 plus/list.php?tid=1替换成plus/list-1.htmltid=后面那个是正整数,替换为list-后面的数字 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php $str = "plus/list.php?tid=1";$pattern = "/\.php\?tid=(\d+)/";$replacement = "-$1.html";print preg_replace($pattern, $replacement, $str);?>是否像这样? tid=1 这个1不是固定的,是数字来的. $url ="plus/list.php?tid=1";echo preg_replace("#plus/list.php\?tid=(.*)#", "plus/list-\${1}.html", $url); 你用(.*)#是匹配数字吗?因为要被替换的代码全部是这样的:<A href="/plus/list.php?tid=1">服饰</A> > <A href="/plus/list.php?tid=11">服饰搭配</A> > <A href="/plus/list.php?tid=17">场合搭配</A> > <A href="/plus/list.php?tid=20">职场</A> > .是匹配除换行符以外的任意字符的 *是任意个这个地方你要是匹配数字的话用 \d +表示1个或1个以上所以你可以改为$url ="plus/list.php?tid=1";echo preg_replace("#plus/list.php\?tid=(\d+)#", "plus/list-\${1}.html", $url); [0-9]\{1,\}正则匹配数字 出现一次以上 在linux下是这样 根据情况\有可能不需要 $str = '<A href="/plus/list.php?tid=1">服饰</A> > <A href="/plus/list.php?tid=11">服饰搭配</A> > <A href="/plus/list.php?tid=17">场合搭配</A> > <A href="/plus/list.php?tid=20">职场</A> >';$s = preg_replace("/list.php\?tid=(\d+)/i", "list-\\1.html", $str);echo $s;嘛,再根據你的頁面鏈接的要求繼續正它如:加上plus/ 等等, 只替換 有帶plus/的鏈接 请教PHP的SSO(单点登录)解决办法??? 有关smarty中display遇到{include file=""}的问题 谁能给我讲讲APACHE解析PHP的原理? Symfony 介绍 超级菜鸟请大家帮忙-用php搜索数据库的问题 php新手问题 PHP如果隐藏后缀名?如www.xxx.com/admin?id=50这样? 请问PHP中有没有直接的函数把12-Apr-2005格式转为2005-04-12 关于PHP和ASP融合的问题 如何实现页面保护 两个数组随机组合成一个字符串 帮忙解释几个程序
$str = "plus/list.php?tid=1";
$pattern = "/\.php\?tid=(\d+)/";
$replacement = "-$1.html";
print preg_replace($pattern, $replacement, $str);
?>
是否像这样?
tid=1 这个1不是固定的,是数字来的.
$url ="plus/list.php?tid=1";
echo preg_replace("#plus/list.php\?tid=(.*)#", "plus/list-\${1}.html", $url);
你用(.*)#是匹配数字吗?因为要被替换的代码全部是这样的:
<A href="/plus/list.php?tid=1">服饰</A>
> <A href="/plus/list.php?tid=11">服饰搭配</A> > <A
href="/plus/list.php?tid=17">场合搭配</A> > <A
href="/plus/list.php?tid=20">职场</A> >
这个地方你要是匹配数字的话用 \d
+表示1个或1个以上
所以你可以改为$url ="plus/list.php?tid=1";
echo preg_replace("#plus/list.php\?tid=(\d+)#", "plus/list-\${1}.html", $url);
正则匹配数字 出现一次以上 在linux下是这样
根据情况\有可能不需要
<A href="/plus/list.php?tid=1">服饰</A>
> <A href="/plus/list.php?tid=11">服饰搭配</A> > <A
href="/plus/list.php?tid=17">场合搭配</A> > <A
href="/plus/list.php?tid=20">职场</A> >
';$s = preg_replace("/list.php\?tid=(\d+)/i", "list-\\1.html", $str);
echo $s;嘛,再根據你的頁面鏈接的要求繼續正它
如:加上plus/ 等等, 只替換 有帶plus/的鏈接