note 96585 deleted from function.preg-split by danbrown

From: Date: Sat, 06 Mar 2010 18:20:59 +0000
Subject: note 96585 deleted from function.preg-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166744@lists.php.net to get a copy of this message
Note Submitter: G.S ---- i searched for a function or regex to get the image src url from a html document i found it somewhere else and wanted to post this here so maybe someone dousnt need to search through half google again <?php function getImageUrls($data){ $images = array(); preg_match_all('/(img|src)\=(\"|\')[^\"\'\>]+/i', $data, $media); unset($data); $data=preg_replace ('/(img|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]); foreach($data as $url) { $info = pathinfo($url); if (isset($info['extension'])) { if (($info['extension'] == 'jpg') || ($info['extension'] == 'jpeg') || ($info['extension'] == 'gif') || ($info['extension'] == 'png')) array_push($images, $url); } } return($images); } //usage $url='http://www.example.com'; $imgArray=getImageUrls(file_get_contents($url)); ?> source: http://davebrooks.wordpress.com/2009/04/22/ php-preg_replace-some-useful-regular-expressions/

« previous php.notes (#166744) next »