我需要在href="之前添加http://如果http://不遵循href="或src="
以下代码部分有效.部分意味着它只考虑<a href="但不考虑src="
$str= preg_replace(
"/(?<!a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i",
"<a href=\"\\0\"> target=\"blank\">\\0</a>",
$str
);
Run Code Online (Sandbox Code Playgroud)
谢谢你们提前回复.
$str= preg_replace(
"/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i",
"<a href=\"\\0\" target=\"blank\">\\0</a>",
$str
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5850 次 |
| 最近记录: |