我正在尝试将URL转换为活动URL。问题在于URL匹配模式还将HTML标记也视为URL。
$url = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/';
$data_new = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $data_new);
我的字符串是:
https://www.google.com/image/</h3>fsdgdgbfhgfn
我得到以下输出:
<a href="https://www.google.com/image/</h3>fsdgdgbfhgfn" target="_blank" title="https://www.google.com/image/</h3>fsdgdgbfhgfn">https://www.google.com/image/</h3>fsdgdgbfhgfn</a>
预期输出:
<a href="https://www.google.com/image/" target="_blank" title="https://www.google.com/image/">https://www.google.com/image/</a></h3>fsdgdgbfhgfn