hi. i need your help. content of word.txt: abc def ghi --EOF-- this is the code <?php $word = file_get_contents("./word.txt"); $wordarray = explode("\n",$word); $string = "Aabc test1 Ddef test2 ghi"; foreach($wordarray as $output) { $string = eregi_replace($output, "", $string); } echo $string; ?> the output is: A test1 D test2 BUT! i want to remove the exact word. i.e. in this case, only ghi to be removed. so the output must be Aabc test1 Ddef test2
When I run that code I get "Aabc test1 Ddef test2" ???? If your still having problems try That also works for me.
you shouldn't be using ereg_replace, as it is considered sort of bad practice and is going to be dropped from php6 I guess. try this: $string = preg_replace("/\b".$output."\b/", "", $string); \b stands for word boundary.