3raser Posted April 7, 2011 Share Posted April 7, 2011 $to_censor = array("f", "a", "e", "r", "c"); $new_censor = array("****", "****", "****", "****", "****"); $new = str_replace($to_censor, $new_censor, $description); Is it possible to do this without having to add a new **** in $new_censor when I add another censored word in $to_censor Link to comment https://forums.phpfreaks.com/topic/232923-str_replace/ Share on other sites More sharing options...
btherl Posted April 7, 2011 Share Posted April 7, 2011 Yes, from the manual page: "If search is an array and replace is a string, then this replacement string is used for every value of search" http://php.net/manual/en/function.str-replace.php All will be the same length though. If you want to preserve length it'll be trickier. Link to comment https://forums.phpfreaks.com/topic/232923-str_replace/#findComment-1197981 Share on other sites More sharing options...
3raser Posted April 7, 2011 Author Share Posted April 7, 2011 Yes, from the manual page: "If search is an array and replace is a string, then this replacement string is used for every value of search" http://php.net/manual/en/function.str-replace.php All will be the same length though. If you want to preserve length it'll be trickier. Thanks, it worked. Link to comment https://forums.phpfreaks.com/topic/232923-str_replace/#findComment-1197984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.