How To Take Cease Words From The String Using Php?

I desire to strip whole bad words from a string wherever they are within the string.
I accept created an array of forbidden words or destination words.
 $string = 'sand band or nor in addition to where whereabouts foo'; $stopwords = array("or", "and", "where"); 
There are 2 ways to accomplish it. For example:
Alternative 1
 echo preg_replace("\b$stopwords\b", "", $string); //output : sand band  nor   whereabouts foo 
Alternative 2
 foreach ($stopwords equally &$word) {     $word = '/\b' . preg_quote($word, '/') . '\b/'; } echo preg_replace($stopwords, '', $string); //output : sand band  nor   whereabouts foo 
Ref: http://codepad.org/lrXknCO4 && http://stackoverflow.com/a/9342200
Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?