note 96585 added to function.preg-split
| From: | G dot S at osu1 dot php dot net | Date: | Sat, 06 Mar 2010 11:04:04 +0000 |
| Subject: | note 96585 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166729@lists.php.net to get a copy of this message | ||
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/
----
Server IP: 69.147.83.197
Probable Submitter: 80.101.198.237
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/96585
Del: integrated -- https://master.php.net/note/delete/96585/integrated
Del: useless -- https://master.php.net/note/delete/96585/useless
Del: bad code -- https://master.php.net/note/delete/96585/bad+code
Del: spam -- https://master.php.net/note/delete/96585/spam
Del: non-english -- https://master.php.net/note/delete/96585/non-english
Del: in docs -- https://master.php.net/note/delete/96585/in+docs
Del: other reasons-- https://master.php.net/note/delete/96585
Reject -- https://master.php.net/note/reject/96585
Search -- https://master.php.net/manage/user-notes.php