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. Link to comment https://forums.phpfreaks.com/topic/48996-preg_replace-nightmare/ 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>|"; Link to comment https://forums.phpfreaks.com/topic/48996-preg_replace-nightmare/#findComment-240017 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>", '/') . '/'; Link to comment https://forums.phpfreaks.com/topic/48996-preg_replace-nightmare/#findComment-240018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.