PHP: remove `http://` from link title

后端 未结 7 1411
终归单人心
终归单人心 2020-12-31 17:34

I have a string that looks like:

$string = \'http://google.com\';

How can I remove the http:

7条回答
  •  时光说笑
    2020-12-31 18:04

    In this simple case, the preg_replace function will probably work. For more stability, try using DOMDocument:

    $string = 'http://google.com';
    $dom = new DOMDocument;
    $dom->loadXML($string);
    
    $link = $dom->firstChild;
    $link->nodeValue = str_replace('http://', '', $link->nodeValue);
    $string = $dom->saveXML($link);
    

提交回复
热议问题