Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when using preg_replace 1

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
I have a php page that imports a html page and displays it, I am trying to use preg_replace to remove a line at the bottom of the imported html page, heres the code I'm using:

<?
$filename = &quot;admin/$id&quot;.&quot;.htm&quot;;
$fd = fopen ($filename , &quot;r&quot;);
$MyStr = fread ($fd, filesize ($filename));
fclose ($fd);
$badStr = &quot;/(<br><font size=1>generated with <a href=\&quot; generator</a></font>)/&quot;);
$goodStr = &quot;&quot;;
$MyStr = preg_replace($badStr, $goodStr, $MyStr);
print $MyStr;
?>

But instead it shows the html page without removing the line that I want removed and shows this error:

Warning: Unknown modifier '/' in // on line 58

Where am I going wrong?

Thanks.
 
Have you tried escaping all the forward slashes in the bad string? I think preg_replace is probably seeing the // in the URL as one / to end the regular expression and the next / as a preg_replace option (like /blah/g to do a global replace). Escape all the forward slashes (those in the URL and in the HTML tags) and see if that helps.

Just a guess. Matt
matt@paperlove.org
If I can help, I will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top