PHP正则表达式替换链接url

Dus*_*Sun 5 php regex

我需要在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)

谢谢你们提前回复.

cha*_*aos 7

$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)