phpregexpreg-replaceeregereg-replace

Need some help upgrading a tiny piece of ereg_replace


I have this line of code I use for SEO purposes. The only thing is that it has an ereg_replace function in it. Now I get "ereg_replace() is deprecated" error.

Apparently it's not as simple as switching it to preg_replace and my RegEx-fu is not too strong. Any help would be highly appreciated.

Thanks.

  //make it lowercase, remove punctuation, remove multiple/leading/ending spaces
    $return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input))));

Solution

  • Here you go.

    $return = trim(preg_replace('/[ ]+/i',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input))));