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 Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/232923-str_replace/#findComment-1197984 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.