php正则表达式替换链接 怎么将 <a href="dd.html" target="_blank">ddd</a>替换成<a href="dd.php?url=dd.html">ddd</a>求解 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str = '<a href="dd.html" target="_blank">ddd</a>';$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";$str = preg_replace($match, "\\1\\2?\\2\\3", $str);echo $str; 上一个有问题$str = '<a href="dd.html" target="_blank">ddd</a>';$match = "/(<a\s+.*?href=\")(.*?)(\")([^>]*?)(>.*)/i";$str = preg_replace($match, "\\1\\2?url=\\2\\3\\5", $str);echo $str; $str = '<a href="dd.html" target="_blank">ddd</a>'; preg_match('/<a[^>]+href\s*=\s*[\'"]([^\'"]*)[\'"][^>]*>([^<\/a>]*)/i',$str,$matches); echo '<a href="dd.php?url=' . $matches[1] . '">' . $matches[2] . '</a>'; <a href="http://wori/et/man.htm?TBG=40980.71104.24&cat=50010158&isprepay=1&random=false&viewIndex=1&yp4p_page=0&commend=all&atype=b&style=grid&olu=yes&isnew=2&smc=1">夹克</a> 没有target 属性 属性怎么弄呢? $str = '<a href="<a href="http://wori/et/man.htm?TBG=40980.71104.24& cat=50010158&isprepay=1&random=false& viewIndex=1&yp4p_page=0&commend=all&atype=b& amp;style=grid&olu=yes&isnew=2&smc=1">夹克< /a>" target="_blank">ddd</a>';$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";$str = preg_replace($match, "\\1\\2?\\2\\3", $str);echo $str; 这样的话不好使 TT 你把你的 $str 整理一下贴出来 你那个太乱了 而且还是转义过的 不好意思写错了$str = '<a href="http://www.baidu.com">abab</a><a href="http://www.baidu.com">dsfs</a><a href="http://www.baidu.com">dsffw</a>';$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);echo $str;这样的话第二个开始就不好使了 $str = '<a href="http://www.baidu.com">abab</a><a href="http://www.baidu.com">dsfs</a><a href="http://www.baidu.com">dsffw</a>';$match = "/(<a\s+.*?href=\")(.*?)(\")/i";$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);echo $str; $str = '<h5><a href="http://www.baidu.com/">fassion</a></h5><span><a class="h" href="http://www.baidu.com/">girl</a> <a href="http://www.baidu.com/">boy</a></span>';$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);echo $str;这样的话又不行了 - -; 麻烦大家了;; $str = '<h5><a href="http://www.baidu.com/">fassion</a></h5><span><a class="h" href="http://www.baidu.com/">girl</a> <a href="http://www.baidu.com/">boy</a></span>';$match = "/(<a\s+.*?href=\")(.*?)(\")([^>]*?>)/i";$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3\\4", $str);echo $str; 这个就是有or没有target的<?php/* * @Date 2011-1-14 * @Author h2ero * Email [email protected] * Blog blog.h2ero.cn */ $str='<a href="dd.html"target="_blank">ddd</a>'; $pattern='/<a (target="(.*)")?href="(.*)\.(.*)"(target="(.*)")>(.*)<\/a>/i'; $replace='<a href="\\3.php?url=\\3.\\4"\\5>\\7</a>'; $result=preg_replace($pattern,$replace,$str); echo $result;?> 查询当月数据 子类使用父类变量 mssql_pconnect出错 php数据库开发 不同php服务器页面验证 请问可不可以通过程序结束一次Session? 实在是没分了,好心人帮忙呀。 为什么,我访问的时候出现下面的情况?谢谢. 哪里有apache的详细配置说明! 求解php和c语言的进程间通信能兼容吗 require_once包含的问题,在线等 PHP AJAX 投票问题
$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";
$str = preg_replace($match, "\\1\\2?\\2\\3", $str);
echo $str;
$match = "/(<a\s+.*?href=\")(.*?)(\")([^>]*?)(>.*)/i";
$str = preg_replace($match, "\\1\\2?url=\\2\\3\\5", $str);
echo $str;
$str = '<a href="dd.html" target="_blank">ddd</a>';
preg_match('/<a[^>]+href\s*=\s*[\'"]([^\'"]*)[\'"][^>]*>([^<\/a>]*)/i',$str,$matches);
echo '<a href="dd.php?url=' . $matches[1] . '">' . $matches[2] . '</a>';
$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";
$str = preg_replace($match, "\\1\\2?\\2\\3", $str);
echo $str;
这样的话不好使 TT
$str = '<a href="http://www.baidu.com">abab</a><a href="http://www.baidu.com">dsfs</a><a href="http://www.baidu.com">dsffw</a>';
$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";
$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);
echo $str;
这样的话第二个开始就不好使了
$str = '<a href="http://www.baidu.com">abab</a><a href="http://www.baidu.com">dsfs</a><a href="http://www.baidu.com">dsffw</a>';
$match = "/(<a\s+.*?href=\")(.*?)(\")/i";
$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);
echo $str;
$match = "/(<a\s+.*?href=\")(.*?)(\".*)/i";
$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3", $str);
echo $str;
这样的话又不行了 - -; 麻烦大家了;;
$match = "/(<a\s+.*?href=\")(.*?)(\")([^>]*?>)/i";
$str = preg_replace($match, "\\1index.php?tblurl=\\2\\3\\4", $str);
echo $str;
<?php
/*
* @Date 2011-1-14
* @Author h2ero
* Email [email protected]
* Blog blog.h2ero.cn
*/
$str='<a href="dd.html"target="_blank">ddd</a>';
$pattern='/<a (target="(.*)")?href="(.*)\.(.*)"(target="(.*)")>(.*)<\/a>/i';
$replace='<a href="\\3.php?url=\\3.\\4"\\5>\\7</a>';
$result=preg_replace($pattern,$replace,$str);
echo $result;
?>