1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need Help Fixing "Deprecated" Function

Discussion in 'PHP' started by gregdavidson, May 1, 2014.

  1. #1

    I just installed a new script on my website and I'm getting this message:

    Deprecated: Function ereg_replace() is deprecated in /home/content/68/9317268/html/YourSite/seourls.php on line 23

    This is the coding that's on line 23:

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

    If you can help me I would greatly appreciate it. Thanks.
    gregdavidson, May 1, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Just remove it.
    $return = trim(preg_replace('/[a-z0-9\s]/','',strtolower($input)));
    does the same thing, as far as I can see.
    PoPSiCLe, May 1, 2014 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Sorry @PoPSiCLe, not the same thing. The e-reg is there to condense multiple spaces to a single space... See that space before the plus?

    Normally I'd assume that's trying to do FULL whitespace compression, in which case I'd go with:
    $return = trim(preg_replace('/\s+/',' ',preg_replace('/[^a-z0-9\s]/','',strtolower($input))));

    * NOTE - I killed off the upper-case check in the regex since it already runs strtolower.

    Though if you literally just want any number of spaces ONLY, just add the slashes...

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

    Though that could be even more simply done since patterns are type mixed -- so you can pass arrays.

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

    I'd go with the \s so ALL whitespace chars are turned into spaces.

    * NOTE - uses PHP 5.4 style arrays.

    Though that is REALLY complex and semi-questionable. I'd be wondering about the data that's being scrubbed by that.
    deathshadow, May 1, 2014 IP