3

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))));
Serhiy
  • 2,505
  • 3
  • 33
  • 49

2 Answers2

3

You just need to add delimeters

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

ereg_replace(' +' becomes preg_replace('/ +/'

Frank Farmer
  • 38,246
  • 12
  • 71
  • 89
3

Here you go.

$return = trim(preg_replace('/[ ]+/i',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input))));
Steve Nguyen
  • 5,854
  • 5
  • 21
  • 39
  • This is the one that actually gives me the correct result. I wish it had more +1 to give. I actually up-voted the other answer first cause it was easier but once I ran tests this gave me the correct result. I can't seem to take away my vote from the other one though. – Serhiy Jul 14 '11 at 21:32
  • 1
    @Serhiy Because I'm a regex badass. I saw his answer and I was like, "puhleaseeeeee, not even close" – Steve Nguyen Jul 14 '11 at 22:23
  • 1
    @Serhiy By the way, your domain "wellcommentedcode.com" is sexy name. – Steve Nguyen Jul 14 '11 at 22:28
  • haha thanks, I really need to do something with it... it's been a long overdue work in progress... your blog "eggheadreport.com" isn't bad either... could expand it to full-blown publication with a name like that... – Serhiy Jul 15 '11 at 08:32