Change a relative URL to absolute URL

前端 未结 3 1009
时光说笑
时光说笑 2020-12-16 06:36

for example i\'ve got a string like this:

$html = \'
            test
            

        
3条回答
  •  Happy的楠姐
    2020-12-16 07:06

    found a good way :

    $html = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#", '$1http://mydomain.com/$2$3', $html);
    

    you can use (?!http|mailto) if you have also mailto links in your $html

提交回复
热议问题