Results 1 to 2 of 2
Thread: Regex Problem
Dec 28, 2008, 20:26 #1
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:
<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
- Boise, ID
- 0 Post(s)
- 0 Thread(s)
Something like this?
$string = '<a id="uniqueid" href="#">
<img src="path-to-image.jpg" />
$matches = array();
preg_match('/id="uniqueid"[^<>]*>\s*<img[^<>]*src="([\w-\.:\/]*)"/i', $string, $matches);
echo $matches . "\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.