eregi_replace help

From: Date: Tue, 08 Oct 2002 00:01:59 +0000
Subject: eregi_replace help
Groups: php.general 
Request: Send a blank email to php-general+get-119093@lists.php.net to get a copy of this message
Hello all, I am trying to use php to read through an html file and replace all image paths, like such: Change "images/firstimage.gif" to "http://www.blah.com/firstimage.gif" ... Change "somesuch/images/secondimage.jpg" to "http://www.blah.com/secondimage.jpg" So I am going through the file and matching the image path strings, stripping them down to just the image name using "basename", and then adding "http://www.blah.com/" onto the beginning of them. Except it's not working, and I'm not sure where my logic has gone awry. Instead of replacing each image path with its respective image name, it is replacing all image paths with the *same* image name. Here is the code. (Yes I'm new, I apologize for the mess, there are a few lines in there I'm using for debugging purposes, to show me what it's doing.) <? $filename = "newexample.html"; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize ($filename)); while (preg_match('{(")([A-z0-9_/-](\/))*[A-z0-9_/-]+(.gif|.jpg)}', $contents, $matches)) { echo "<b>MATCHED:</b> ".$matches[0]."<br>\n"; $base = basename($matches[0]); $newimage = "http://www.blah.com/".$base; echo "<br>base: ".$base."<br>"; echo "new image: ".$newimage."<br>"; echo "<hr>"; $contents = eregi_replace('\/*[A-z0-9_/-]+(.gif|.jpg)', $newimage, $contents); print $contents; } fclose ($fd); ?> When I run it, I get: ~~~~~ MATCHED: "blah/images/first.gif base: first.gif new image: http://www.blah.com/first.gif ------------------------------------------------------------------------ <Here it prints the contents of the html file, except all images look like "http://www.blah.com/first.gif" (when there are supposed to be lots of other images, such as second.jpg, etc).> ~~~~~ Where have I gone wrong? Thanks to all, as usual, for your hints and help. Jen

« previous php.general (#119093) next »