Discover Centmin Mod today
Register Now

Sysadmin Help concert regex expression from ereg to preg_match

Discussion in 'System Administration' started by Andy, Apr 6, 2018.

  1. Andy

    Andy Premium Member Premium Member

    420
    60
    28
    Aug 6, 2014
    Ratings:
    +84
    Local Time:
    8:23 AM
    I have a few ereg expressions that no longer work in PHP 7 and I read that the equivalence is preg_match

    Would really appreciate if anyone with experience can help with how to convert those.
    Code:
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {

     
  2. pamamolf

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    3:23 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Isn't that bash code not related to php ?

    Sorry for the stupid question but i am not a developer and i am just wondering on that as it doesn't seem as php code to me :)
     
  3. Andy

    Andy Premium Member Premium Member

    420
    60
    28
    Aug 6, 2014
    Ratings:
    +84
    Local Time:
    8:23 AM
    It's part of a PHP file in wordpress
     
  4. pamamolf

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    3:23 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    First backup and then try :)

    Code:
    preg_match('/if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {/i', '', $result);
    preg_match('/if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {/i', '', $result);
    preg_match('/if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {/i', '', $result);
    or

    Code:
    preg_match('/if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {/', '', $result);
    preg_match('/if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {/', '', $result);
    preg_match('/if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {/', '', $result);
    I must do some homework about developing :p Don't know nothing :)
     
    Last edited: Apr 6, 2018
  5. Andy

    Andy Premium Member Premium Member

    420
    60
    28
    Aug 6, 2014
    Ratings:
    +84
    Local Time:
    8:23 AM
    not going to work, you need to replace ereg
     
  6. pamamolf

    pamamolf Well-Known Member

    3,117
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    3:23 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Ok sorry then :(

    You may need to wait for experts to get a proper advice.
     
    • Like Like x 1
  7. Andy

    Andy Premium Member Premium Member

    420
    60
    28
    Aug 6, 2014
    Ratings:
    +84
    Local Time:
    8:23 AM
    Was able to find a solution by replacing ereg with mb_ereg which is direct replacement function and not deprecated in PHP 7.
     
    • Like Like x 1
..