0

How can I adjust my code by replacing the "eregi_replace" function with another one that does the same thing?

I know the alternatives, but I do not know how to update the code. O erro que recebo é:

PHP Deprecated: Function eregi_replace

function url($String){

    $Separador = "-";

    $String = trim($String);
    $String = strtolower($String);
    $String = strip_tags($String);
    $String = eregi_replace("[[:space:]]", $Separador, $String); 

    $String = eregi_replace("[çÇ]", "c", $String);
    $String = eregi_replace("[áÁäÄàÀãÃâÂ]", "a", $String);
    $String = eregi_replace("[éÉëËèÈêÊ]", "e", $String);
    $String = eregi_replace("[íÍïÏìÌîÎ]", "i", $String);
    $String = eregi_replace("[óÓöÖòÒõÕôÔ]", "o", $String);
    $String = eregi_replace("[úÚüÜùÙûÛ]", "u", $String);

    $String = eregi_replace("(\()|(\))", $Separador, $String);
    $String = eregi_replace("(\/)|(\\\)", $Separador, $String);
    $String = eregi_replace("(\[)|(\])", $Separador, $String);
    $String = eregi_replace("[@®#\$%&\*\+=\|º]", $Separador, $String);
    $String = eregi_replace("[;:'\"<>,\.?!_]", $Separador, $String);
    $String = eregi_replace("[“”]", $Separador, $String);
    $String = eregi_replace("(ª)+", $Separador, $String);
    $String = eregi_replace("[´~^°]", $Separador, $String);

    $String = eregi_replace("($Separador)+", $Separador, $String);
    $String = substr($String, 0, 100);
    $String = eregi_replace("(^($Separador)+)|(($Separador)+$)", "", $String);
    $String = str_replace("-", $Separador, $String);

    return $String;
}
revo
  • 47,783
  • 14
  • 74
  • 117
Clebson
  • 296
  • 1
  • 12
  • What is the problem you have when you replace the `eregi_replace()` function with the alternatives? – Progman Nov 12 '18 at 19:33
  • I'm not aware, I've tried using the following alternatives: http://www.php.net/manual/en/ref.pcre.php. I do not know which one is correct, but I just replace the word `eregi_replace` with the alternative, and none worked. – Clebson Nov 12 '18 at 19:44
  • 1
    The PHP docs point to `preg_replace` using the `i` modifier for case insensitivity. A quick check of the docs - http://php.net/manual/en/function.preg-replace.php - makes it seem like you just need to replace your `eregi_replace` with `preg_replace`. – ivanivan Nov 12 '18 at 19:45
  • PHP Warning: preg_replace(): Compilation failed: POSIX named classes are supported only within a class at offset 0 in – Clebson Nov 12 '18 at 19:47
  • You need delimiters in all patterns, try `/` as `$String = preg_replace("/[[:space:]]/i", $Separador, $String);`. Obviously you won't need the `i` in all patterns since spaces etc. don't have case. – AbraCadaver Nov 12 '18 at 19:56
  • And actually you're converting them to lowercase with `strtolower()` and have the upper and lower in the pattern as well, so probably don't need it at all ;-) – AbraCadaver Nov 12 '18 at 20:04
  • That code is ridiculous... If you actually know what it's doing, what a waste of space. – ArtisticPhoenix Nov 12 '18 at 20:07

0 Answers0