[PHP] get all URLs from text

Here is the way to get all URLs from text.
以下方法可以把全部連結拿出來.

function findURLs($text){
$pattern = '/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?/i';
@preg_match_all($pattern, $text, $matches);
if($matches[0]){
return $matches[0];
}else{
return false;
}
}

留言

這個網誌中的熱門文章

How to PHP export to Excel 2

html viewport meta