oshlo.blogspot.com - I want to strip whole bad words from a string wherever they are inside the string.
I have created an array of forbidden words or stop words.
$string = 'sand band or nor and where whereabouts foo'; $stopwords = array("or", "and", "where");There are two ways to achieve it. For example:
Alternative 1
echo preg_replace("\b$stopwords\b", "", $string); //output : sand band nor whereabouts fooAlternative 2
foreach ($stopwords as &$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
other source : http://youtube.com, http://docstoc.com, http://developer-paradize.blogspot.com
0 Response to "[DOM parser] How To Remove Stop words From The String Using PHP?"
Posting Komentar