Hi guys, below are simple replacing script a word in to another word, or censorship $word = array( 'google', 'yahoo' ); $link = array( 'go*gle', 'yah*o' ); $this->post['message'] = str_ireplace($word, $link, $this->post['message']); PHP: the problem its currently also replacing another words like into please help how to make it only replacing exact words? GBU for all that answering
Preg_replace along with the word boundary should do the trick: <?php $string = 'google yahoo test yahoo'; $find = array('/\bgoogle\b/', '/\byahoo\b/'); $replace = array('go*gle', 'yaho*'); echo preg_replace($find, $replace, $string); PHP:
That would take place instead of the original string and takes the results of preg_replace instead of outputting it.