#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Ereg is deprecated errors in PHP 5.3


    I get these deprecated errors and am fixing those, replacing ereg to preg and so on but I canīt get some working for some reason. My question is when I really need to get rid of ereg, when will it stop working? If it would just stop working so would the site. Confused and worries. Please advise. Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,003
    Rep Power
    376
    not sure when ereg will stop working but i wouldnt wait for that, i would start using preg straight away.

    And yeah when they stop working, you will probably get PHP errors saying function not available/valid or whatever and your user will either see a blank screen or the error depending on how you handle errors
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    I have about 400 files. Do I really need to manually change every file because of that?

    I canīt get one replacement working, am I missing someting?

    $lice = ereg_replace("^" . PRODUCT_ID, "", $l);

    should become...

    $lice = preg_replace("#^#" . PRODUCT_ID, "", $l);


    feeling really noobish :/
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    ereg() will go away "soon". I don't know of any concrete plans when to remove it but it is definitely going away. Besides, the preg_* functions are faster and more powerful anyways.

    In that example you don't even need regular expressions. "If the string starts with the PRODUCT_ID then remove it."
    PHP Code:
    if(strncmp($lPRODUCT_IDstrlen(PRODUCT_ID)) == 0) {
        
    $l substr($lstrlen(PRODUCT_ID));

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Ithaca
    Posts
    68
    Rep Power
    2
    I had the same problem before with my software 2 years ago, all I did was to change ereg_match() to preg_match(), ereg_replace() to preg_replace() and its been working perfectly fine for me since then.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Originally Posted by Hall of Famer
    I had the same problem before with my software 2 years ago, all I did was to change ereg_match() to preg_match(), ereg_replace() to preg_replace() and its been working perfectly fine for me since then.
    It... does take a little more work than that. Have to add delimiters, for one. But yes, for the most part the ereg/POSIX syntax is a subset of the preg/PCRE syntax.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Ithaca
    Posts
    68
    Rep Power
    2
    Originally Posted by requinix
    It... does take a little more work than that. Have to add delimiters, for one. But yes, for the most part the ereg/POSIX syntax is a subset of the preg/PCRE syntax.
    Yeah thats right, if you use lots of complex ereg expressions you will likely to end up having to make more fixes than simply replacing ereg by preg(luckily for me, I only had minor email regular expression check with ereg). Its still a very good idea to start with though as it cuts down the size of your problem and reduces the cost of refactoring. Whatever isnt suffice, isolate them after fixing the others and then concentrate on this much smaller set of problem.
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    By the way, the ereg_* function have been obsolete for a looong time. As far as I can tell, PCRE was added around 2000.

    This means your application hasn't been touched for at least a decade, so don't expect this to be a quick fix. You're likely to encounter other issues, because the PHP of the late 90s is different from the PHP of today.

    By the way, when you insert dynamic input into a regex, you must escape it:

    PHP Code:
    $result preg_replace('#^' preg_quote($search'#') . '#'''$haystack); 
    Otherwise, even a simple dot will break the whole thing, because it's interpreted as a regex dot.

    The best solution is to avoid regexes if possible and use simple string operations like the one shown by requinix.
    The 6 worst sins of security • How to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo