This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

[DOM parser] How To Remove Stop words From The String Using PHP?

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 foo 
Alternative 2
 foreach ($stopwords as &$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

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

Contact

Nama

Email *

Pesan *