note 49662 deleted from function.preg-match-all by nlopess

From: Date: Wed, 07 Dec 2005 22:09:44 +0000
Subject: note 49662 deleted from function.preg-match-all by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-99710@lists.php.net to get a copy of this message
Note Submitter: rickyale at ig dot com dot br ---- 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 ) )

« previous php.notes (#99710) next »