note 49662 added to function.preg-match-all

From: Date: Fri, 04 Feb 2005 04:59:54 +0000
Subject: note 49662 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-84498@lists.php.net to get a copy of this message
this function returns an array with a list of all urls matched in a string, including src, href and url; function get_urls($string) { $types = array("href", "src", "url"); while(list(,$type) = each($types)) { preg_match_all ("|$type\=\"?'??([[:alnum:]:?=&@/._-]+)\"?'??|i", $string, &$matches); $ret[$type] = $matches[1]; } return $ret; } $html = implode(file( 'http://www.uol.com.br/' )); print_r(get_urls($html)); ========================= this will return something like this: Array ( [href] => Array ( [0] => http://home.img.uol.com.br/favicon.ico [1] => http://click.uol.com.br/?dqwdqwdqw=232 [2] => http://bandalarga.uol.com.br/ ) [src] => Array ( [0] => http://home.img.uol.com.br/x.gif [3] => http://home.img.uol.com.br/x.gif [4] => http://home.img.uol.com.br/x.gif ) [url] => Array - [for meta refresh tags] ( [0] => http://cinema.uol.com.br/estreias.jhtm ) ) ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49662 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49662&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49662&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49662&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49662&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49662&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49662&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84498) next »