I need help with some regular expression matching.

Here is what I am doing.  In one php file, I'm reading
in the contents of an html file.  Both reside on the
same server.  What I need to do is change all image
tags that are like this:

<img src="directory1/directory2/directoryN/image.gif">

To this:

<img src="image.gif">

I know that "basename" works if you have something
like $path = "/directory1/image.gif"... $file =
basename($path) will return image.gif, which is what I
want.

But... how do I use ereg_replace (probably) and
basename together while reading this file?

The php file I currently have, which does read in the
file, is:

<?
$filename = "example.html";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
print $contents;
fclose ($fd);
?>

So, I'd want to add something like...

$contents =
ereg_replace("/src=\"[A-z0-9_\-\/]*\..+(gif|jpg)\"/",
"src=\"blah.jpg\"", $contents);

Um, except I know the regular expression is wrong
(haven't completely figured that out yet) and I
*don't* want to replace the image name with
"blah.jpg"... I was just using this line to test.

It seems like I should be able to go through and find
each path to each image, basename it, and replace it
with just the image name.  But how?  There will be
multiple numbers of img tags in the html file.

Thank you profusely in advance.
Jen
[EMAIL PROTECTED]

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to