my webhost company moved my site to a different server with (apparently) a different version of PHP

I started getting a deprecated warning message about ereg_replace

given that my website is live and I'm not a php coder by profession, I'd like to double check my ereg_replace replacement before inserting it.

So. At present in the code is:

$Meta_Description = ereg_replace( ' +', ' ', substr(strip_tags(str_replace("</", " </", stripslashes($Meta_Description))), 0, 500));

I think I should make this replacement:

$Meta_Description = preg_replace( '#[ +]#', ' ', substr(strip_tags(str_replace("</", " </", stripslashes($Meta_Description))), 0, 500));

Can someone comment?

Many thanks!

    I would get rid of the square brackets, as that is changing the meaning of the original regexp from "one or more consecutive spaces" to "any one character that is either a space or a plus symbol".

      NogDog;11038833 wrote:

      I would get rid of the square brackets, as that is changing the meaning of the original regexp from "one or more consecutive spaces" to "any one character that is either a space or a plus symbol".

      Ahh, thank you!

        But why bother with inserting a space that will be removed?

        str_replace("</", " </", …);
        

        changes "</" into " </" - i.e. insert a space character

        preg_replace('# +', '', …);
        

        replaces one or more spaces (as many as possible) with the empty string - i.e. strip all space characters which would turn " </" into "</".

          It's not apparent because the OP didn't use the appropriate markup tags (namely [noparse]

          ...

          [/noparse], but there is a space between [font=monospace]'[/font] and [font=monospace]'[/font].

            Write a Reply...