Ceox Posted February 23, 2009 Share Posted February 23, 2009 Hey, I have many words in an array, that I need to replace with other text in a sentence. Here's what I got: $bfile = file("banned_words.txt"); $toclean = $words; $bfile = file("banned_words.txt"); // one word on each row for($i = 0; $i < count($bfile); $i++) { $replace = "xxx"; $toclean = str_replace($bfile[$i], $replace, $toclean); } This only replaces the last word in the array. What can I do to make it work? - Max Link to comment https://forums.phpfreaks.com/topic/146524-php-str_replace-same-subject-as-variable/ Share on other sites More sharing options...
rhodesa Posted February 23, 2009 Share Posted February 23, 2009 i think they will all have new line characters in them...try this: $toclean = str_replace(array_map("trim",file("banned_words.txt")),"xxx",$toclean); Link to comment https://forums.phpfreaks.com/topic/146524-php-str_replace-same-subject-as-variable/#findComment-769250 Share on other sites More sharing options...
Ceox Posted February 23, 2009 Author Share Posted February 23, 2009 Ahh, ofcourse! Thanks a lot Link to comment https://forums.phpfreaks.com/topic/146524-php-str_replace-same-subject-as-variable/#findComment-769267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.