I have a function that cleans a search term before searching it (so you wouldn't search for commas, question marks, etc.). But how do I make it remove numbers only if they're not independent? I believe that's what Google somehow does.
Code: Select all
function cleanhouse($str) {
$str = preg_replace('/[\d\\\?\=\+\&\`\~\!\@\#\$\%\^\*\(\)\; \,\.\/\_]/', ' ',$str); // Leaving just words, but missing independent numbers
$str = trim(preg_replace('/\s\s+/', ' ', $str)); // Cleaning space leftovers from above - would it be faster to run the trim first?
return $str;
}
echo cleanhouse("bla, what's up?"); // bla what's up (good) - BTW, I kept the single quote to avoid the bad search term "what s up"
echo cleanhouse('bla?!'); // bla (good)
echo cleanhouse('bla 1'); // bla (good)
echo cleanhouse('bla1'); // bla (bad)
echo cleanhouse('bla-1'); // bla (bad)