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.
Alternative 1
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 fooAlternative 2
foreach ($stopwords equally &$word) { $word = '/\b' . preg_quote($word, '/') . '\b/'; } echo preg_replace($stopwords, '', $string); //output : sand band nor whereabouts fooRef: http://codepad.org/lrXknCO4 && http://stackoverflow.com/a/9342200 Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment