mocapoke Posted April 27, 2007 Share Posted April 27, 2007 Why is this preg_replace emptying the string rather than replacing it... $string = file_get_contents("http://mocapoke.com/blogReader/select_list.html"); $pattern = "<option value='$filetitle'>$y</option>"; $newscon = preg_replace($pattern,"",$string); echo $newscon; Even if I enter a string to replace it with, the string is still empty... for example: If I change the code to this: $string = file_get_contents("http://mocapoke.com/blogReader/select_list.html"); $pattern = "<option value='$filetitle'>$y</option>"; $newscon = preg_replace($pattern,"REPLACED",$string); echo $newscon; REPLACED won't be printed. Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 27, 2007 Share Posted April 27, 2007 Your pattern is missing delimiters. Typically forward slashes or pipes are used: $pattern = "|<option value='$filetitle'>$y</option>|"; Quote Link to comment Share on other sites More sharing options...
effigy Posted April 27, 2007 Share Posted April 27, 2007 Your pattern needs delimiters. Try this: $pattern = '/' . preg_quote("<option value='$filetitle'>$y</option>", '/') . '/'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.