I have the following function, I want it to remove "alpha" when only one word is not an integral part of a word like alphadog. Now, instead, I just see a βdog,β and that's not good. Any help?
function stripwords($string) { // build pattern once static $pattern = null; if ($pattern === null) { // pull words to remove from somewhere $words = array('alpha', 'beta', '-'); // escape special characters foreach ($words as &$word) { $word = preg_quote($word, '#'); } // combine to regex $pattern = '#\b(' . join('|', $words) . ')\b\s*#iS'; } $print = preg_replace($pattern, '', $string); list($firstpart)=explode('+', $print); return $firstpart; }
edit: hi, I have another problem ... I edited above with a new version of the function: it breaks the words, adjusts the spaces, and then does something else that I need, but it does not remove the dash (or minus) .. . what's wrong? I tried something but to no avail ... thanks
source share