Extract URLs from text in PHP

后端 未结 14 2310
野趣味
野趣味 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 14:00

    preg_match_all('/[a-z]+:\/\/\S+/', $string, $matches);
    

    This is an easy way that'd work for a lot of cases, not all. All the matches are put in $matches. Note that this do not cover links in anchor elements (

提交回复
热议问题