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

后端 未结 7 1520
终归单人心
终归单人心 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:08

    Without using a full blown parser, this may do the trick for most situations...

    $str = 'http://google.com';
    
    $regex = '/(?google.com"
    

    It uses a negative lookbehind to make sure there is no href=" or href=' preceding it.

    See it on IDEone.

    It also takes into account people who delimit their attribute values with '.

提交回复
热议问题