Extract URLs from text in PHP

后端 未结 14 2291
野趣味
野趣味 2020-11-22 13:29

I have this text:

$string = \"this is my friend\'s website http://example.com I think it is coll\";

How can I extract the link into another

14条回答
  •  再見小時候
    2020-11-22 13:47

    There are a lot of edge cases with urls. Like url could contain brackets or not contain protocol etc. Thats why regex is not enough.

    I created a PHP library that could deal with lots of edge cases: Url highlight.

    Example:

    getUrls("this is my friend's website http://example.com I think it is coll");
    // return: ['http://example.com']
    

    For more details see readme. For covered url cases see test.

提交回复
热议问题