Possible Duplicate:
Dynamically replace the “src” attributes of all <img> tags
Funny story: I posted this very question a short time ago, but instead of getting something I could, you know, use, all I got was a lot of dogma about the evils of using regex to parse HTML. So here goes again.
I have some HTML and want to replace the "src" attributes of all the img tags so that they point to copies of the identical images (although with different file names) on another host.
For instance, given these three tags
<IMG SRC="../graphics/pumpkin.gif" ALT="pumpkin">
<IMG BORDER="5" SRC="redball.gif" ALT="*">
<img alt="cool image" src="http://www.crunch.com/pic.jpg"/>
I would like them replaced with
<IMG SRC="http://myhost.com/cache/img001.gif" ALT="pumpkin">
<IMG BORDER="5" SRC="http://myhost.com/cache/img002.gif" ALT="*">
<img alt="cool image" src="http://myhost.com/cache/img003.jpg"/>
I am trying to use PHP Simple HTML DOM Parser, but I'm not getting it.
include 'simple_html_dom.php';
$html = str_get_html('<html><body>
<IMG SRC="../graphics/pumpkin.gif" ALT="pumpkin">
<IMG BORDER="5" SRC="redball.gif" ALT="*">
<img alt="cool image" src="http://www.crunch.com/pic.jpg"/>
</body></html>');
What do I do next?
If you care to go the way of DOMDocument():
The link you posted has the answer:
Of course, you will need to modify the tag/attribute/value names to meet your specific needs.