怎么将 <a href="dd.html" target="_blank">ddd</a>替换成<a href="dd.php?url=dd.html">ddd</a>求解
解决方案 »
- 使用webservice得到json数据,是xsd格式的,如何用php将xsd格式文件生成xml文件?给点思路或者提示,谢谢
- php连接数据库用户名不支持中文,怎么解决
- php header头文件
- xml.php 处理 xml 文件提示错误 代码附 谢谢
- 怎样激活js对话框脚本?
- 这段程序总是无法在生成的界面中提交数据,总是提示带星号的信息未填完整,但我确实已经填完整了
- 用textarea提交了一篇文章,却发现所有的格式都乱了,请教大家
- php4中的对象问题
- 请问appserv 有没有linux版本
- php搜索查询mysql数据并显示
- 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;
?>