我有一个字符串,需要替换<a>
html标签中的任何url
$str='Lorem Ipsum is simply dummy text of http://www.lipsum.com/ the printing';
$outputString=
'Lorem Ipsum is simply dummy text of <a href="http://www.lipsum.com">http://www.lipsum.com/</a> the printing';
$str='Lorem Ipsum is simply dummy text of http://www.lipsum.com/ the printing';
$pattern='/'b((https?:'/'/|www.)['w.'/-?=&#]+)(?='s)/i';
$replace='<a href="$1">$1</a>';
echo preg_replace($pattern, $replace, $str);
输出:
Lorem Ipsum is simply dummy text of <a href="http://www.lipsum.com/">http://www.lipsum.com/</a> the printing'
正在RegExr 上工作