|
-
Jun 26th, 2008, 12:48 PM
#1
Thread Starter
Frenzied Member
How to filter preg_match_all result
Hi all .i am using the following code to get the image thumb and url from a remote html .The code is working but the problem is that it outputs some unwanted images !! could any one help me so i can output only those images that are like the give html and omit the rest.Thanks
PHP Code:
$photos = "http://www.somesite.com/images.html";
curl_setopt($ch, CURLOPT_URL, $photos);
curl_setopt($ch, CURLOPT_POST, 0);
$pagecontents = curl_exec($ch);
$pattern = "/src=[\"‘]?([^\"’]?.*(png|jpg|gif))[\"’]?/i";
preg_match_all($pattern, $pagecontents, $matches);
$count = count($matches[1]);
echo $count;
html of images to consider:
HTML Code:
<div class="photo_index_item">
<div id="dvImgListHypImage">
<a id="ctl00_cpMain_UserViewPictureControl_ImageListings1_dlImageList_ctl14_hypImage" title="image name" class="photo_image" href="http://www.somsite.com/imagelink2"><img title="image name" src="http://www.somesite.com/m_d1288db7a7c2ab5c34b521ac62eb3e43.jpg" style="border-width:0px;" /></a>
</div>
-
Jun 27th, 2008, 04:20 AM
#2
Hyperactive Member
Re: How to filter preg_match_all result
PHP Code:
foreach($matches as $key => $match) {
if(!preg_match("the html you want to match", $match)) {
unset($matches[$key]);
}
}
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Jun 27th, 2008, 04:27 AM
#3
Thread Starter
Frenzied Member
Re: How to filter preg_match_all result
Rudi thanks for your reply. could you explain to me how it works ? i don't know what you mean by the html you want ot match ? All i want to collect http://www.somesite.com/m_d1288db7a7...ac62eb3e43.jpg
only when it appears with in <div> only and omit the rest of images that are outside of <div>
-
Jun 27th, 2008, 04:34 AM
#4
Hyperactive Member
Re: How to filter preg_match_all result
HTML Code:
<div class="photo_index_item">
<div id="dvImgListHypImage">
<a id="ctl00_cpMain_UserViewPictureControl_ImageListings1_dlImageList_ctl14_hypImage" title="image name" class="photo_image" href="http://www.somsite.com/imagelink2"><img title="image name" src="http://www.somesite.com/m_d1288db7a7c2ab5c34b521ac62eb3e43.jpg" style="border-width:0px;" /></a>
</div>
Well you posted this so I assume you mean this.
I don't see why you just don't alter your original expression to have the containing <div> though.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|