View Full Version : Preg Match/Regular expressions question.
08-08-2007, 11:22 PM
I'm trying to pull the image url out of this string:
preg_match("'<img src=(.*?)></a>'si", $finalArray[$plusOne], $out_imageinfo);
list($width, $height) = getimagesize("$out_imageinfo");
Warning: getimagesize(<img src="http://theimagehost.com/theimage.jpg"></a>)
Obviously I'm getting the entire string... I just want the url. I have been trying to figure it out with: http://www.regular-expressions.info/, but no luck yet...
I'm trying to use...
preg_split("'<img src=(.*?)></a>'si", $finalArray[$plusOne], $out_imageinfo);
It won't do anything?
Yeah that's because your splitting the whole instance of <img> out, here is an example:
$image = "<img src=\"picture.jpg\" />";
list($tag, $img, $tag2) = split("[\"]+", $image, 3);
the output is picture.jpg and if it is in a directory it will show the directory aswell
what I did is to go through the string $image and split the string each time it found a "
08-10-2007, 09:18 AM
Actually, that doesn't help... Because I'm trying to strip it out of string that contains multiple URLSs of different types.
However, the string only contains one instance of: "jpg"
So, what I'm trying to do is more like: REGEX: "^<(http)[*?](.jpg)/si" - Try to find a string that starts with http, and ends in JPG, and doesn't contain any <'s.
But, I can't get it to work at all. I'm new to RegEX.
I can't get this to do anything other than echo ArrayArrayArrayArray.........
preg_match_all("/'http'(.+?)'jpg'/", $image, $matches);
$array = $matches;
And, here is an actual string I'm trying to parse and image out of...
$data = "<a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=3180342\" id=\"ctl00_Main_ctl00_UserFriends1_FriendRepeater_ctl02_friendLink\">Jeff</a><br><a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=3180342\" id=\"ctl00_Main_ctl00_UserFriends1_FriendRepeater_ctl02_friendImageLink\"><img src=\"http://a267.ac-images.myspacecdn.com/00220/66/23/220403266_s.jpg\">" ;
$regex = '^</http(.+?)jpg/si';
$image = "<img src=\"http://sumurl.com/picture.jpg\" />";
preg_match("<[a-zA-Z0-9_-]*.jpg>", $image, $match, PREG_OFFSET_CAPTURE, 1);
$image_array = $match;
$image_name = $image_array;
and if it is multiple urls in a string why dont u split them up then do a foreach loop and run them through the preg_match to extract the image name?
08-10-2007, 10:03 AM
I just got this to work, but it cuts out the "jpg" part, hows it doing that? Oh wait, Ic... Hum... Ill just append "jpg", that works...
$regex = '/<img src=\"([^\"]*)(jpg)/iU';
$array = $match;
echo "<br><br> $array";
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.