Extract URLs from text in PHP

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

    preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+".
                    "(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/",
                    $var, &$matches);
    
    $matches = $matches[1];
    $list = array();
    
    foreach($matches as $var)
    {    
        print($var."
    "); }

提交回复
热议问题