SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Regex Problem
-
Dec 28, 2008, 20:26 #1
Regex Problem
I'm trying to read the address of an image located on another web page. The image is wrapped in an anchor tag that has an id attached to it. The html for the link and the image appears like this:
Code:<a id="uniqueid" href="#"> <img src="path-to-image.jpg" /> </a>
I could just read the next line in the file, but I'm afraid if they ever altered the white space on the other page, my code would stop working properly. Any thoughts?
-
Dec 28, 2008, 22:05 #2
- Join Date
- Jan 2006
- Location
- Boise, ID
- Posts
- 556
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like this?
PHP Code:$string = '<a id="uniqueid" href="#">
<img src="path-to-image.jpg" />
</a>';
$matches = array();
preg_match('/id="uniqueid"[^<>]*>\s*<img[^<>]*src="([\w-\.:\/]*)"/i', $string, $matches);
echo $matches[1] . "\n";
Brad Hanson, Web Applications & Scalability Specialist
► Is your website outgrowing its current hosting solution?
► PM me for a FREE scalability consult!
► USA Based: Available by Phone, Skype, AIM, and E-mail.
Bookmarks