note 68608 deleted from function.preg-match-all by colder

From: Date: Mon, 16 Apr 2007 17:04:44 +0000
Subject: note 68608 deleted from function.preg-match-all by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125474@lists.php.net to get a copy of this message
Note Submitter: krzysztof at uno dot pl ---- <?PHP // GET all links from URL function remove_html(&$item, $key) { $item=trim(strip_tags($item)); } function get_links($url) { $preg = "/a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>" ."([^<]+|.*?)?<\/a>/"; preg_match_all(trim($preg), file_get_contents($url), $out, PREG_PATTERN_ORDER); $keys = $out[1]; $values = $out[2]; array_walk($values, 'remove_html'); return (array_combine($keys, $values)); } print_r(get_links("http://www.uno.pl")); /* Result: array ( [/] => [/downloads.php] => PHP 5.1.2 [http://www.php.net/docs.php] => manual [http://www.uno.pl] => My link 1 ... ) */ ?>

« previous php.notes (#125474) next »