.josh Posted September 6, 2012 Share Posted September 6, 2012 We get posts asking about this error on a fairly regular basis, so here's a sticky detailing the error and what to do to fix it. PHP has a number of POSIX regex functions for performing regex matching/replacing/splitting. All of these functions are deprecated, which means they are currently still available in php, but are going to eventually be removed from a future version of PHP. This is an "annoyance" to you now, because it causes an error, which may or may not show up, depending on what your error reporting settings are. This is bad news for you in the future, because your code will break when you upgrade to a future version of PHP that no longer supports these functions. The solution is to convert the POSIX functions to one of the PCRE regex functions instead. Here is the manual entry summarizing the differences, as well as what the PCRE function replacements are. For most cases, you simply have to pick the PCRE equivalent and wrap a delimiter around your pattern. You may also need to use the i modifier if you are using a case-insensitive POSIX function (eg: eregi vs. ereg). Example: Check if a username is only numbers, letters (case-insensitive) and 6-12 chars long. POSIX regex if ( eregi("[a-z0-9]{6,12}",$username) ) { // good username! } else { // bad username! } PCRE regex if ( preg_match("~[a-z0-9]{6,12}~i",$username) ) { // good username! } else { // bad username! } In the PCRE regex example, I use ~ as the delimiter and added the i modifier to make the regex case-insenstive. If doing this doesn't fix your problem, then more than likely your pattern itself has POSIX-specific stuff in it, and you will need to change that, in which case, feel free to post in this forum asking for help. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/ Share on other sites More sharing options...
xyph Posted September 6, 2012 Share Posted September 6, 2012 Much needed. The manual entry is very well done, and this is just icing on the cake! Now we just need a sticky for the 'expects a resource - boolean given' Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1375865 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Much needed. The manual entry is very well done, and this is just icing on the cake! Now we just need a sticky for the 'expects a resource - boolean given' Agreed, on both points. I can volunteer to write that one, if you guys will proof it for me Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376041 Share on other sites More sharing options...
xyph Posted September 7, 2012 Share Posted September 7, 2012 Much needed. The manual entry is very well done, and this is just icing on the cake! Now we just need a sticky for the 'expects a resource - boolean given' Agreed, on both points. I can volunteer to write that one, if you guys will proof it for me Talk is cheap! Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376054 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 I've actually been working on some tutorials for my own blog which is not yet launched, I was going to do one on debugging the mysql/i errors like that. I'll start working on it now :-P Give me something to do this weekend in my 20 minutes of free time when the baby is asleep Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376057 Share on other sites More sharing options...
DavidAM Posted September 7, 2012 Share Posted September 7, 2012 @.josh ... All of these functions are deprecated, which means they are currently still available in php, but are going to eventually be removed from a future version of PHP. ... Does this include the multi-byte versions; i.e. mb_ereg_match? I ask this because I have never seen the mb_ereg* functions mentioned in relation to any discussion on regular expressions. I just think it would be good to make the sticky "complete" by mentioning these one way or the other. I came across them (in the manual) recently. while I was reworking my site into utf-8. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376125 Share on other sites More sharing options...
premiso Posted September 7, 2012 Share Posted September 7, 2012 @.josh ... All of these functions are deprecated, which means they are currently still available in php, but are going to eventually be removed from a future version of PHP. ... Does this include the multi-byte versions; i.e. mb_ereg_match? I does not appear to be so. The first source would be the manual, and since there is no big pink "Depreciated" message it has not been thought of being depreciated. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376138 Share on other sites More sharing options...
salathe Posted September 7, 2012 Share Posted September 7, 2012 Does this include the multi-byte versions; i.e. mb_ereg_match? No, the mbstring regex functions are not deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376139 Share on other sites More sharing options...
.josh Posted September 7, 2012 Author Share Posted September 7, 2012 Does this include the multi-byte versions; i.e. mb_ereg_match? No, the mbstring regex functions are not deprecated. Was that an oversight, or did they specifically decide to make an exception? Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376141 Share on other sites More sharing options...
xyph Posted September 7, 2012 Share Posted September 7, 2012 mbstring is a different extension than ereg. Why mbstring uses POSIX rather than PCRE, I don't know Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376181 Share on other sites More sharing options...
salathe Posted September 8, 2012 Share Posted September 8, 2012 Was that an oversight, or did they specifically decide to make an exception? The mbstring regex functions are only similar by name. They use the Oniguruma regex engine to get the work done, not POSIX nor PCRE. Only the POSIX family of functions are deprecated at this time. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376285 Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 How's this? At least a starting point hopefully. http://forums.phpfreaks.com/index.php?topic=365029.msg1730174#msg1730174 Much needed. The manual entry is very well done, and this is just icing on the cake! Now we just need a sticky for the 'expects a resource - boolean given' Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376767 Share on other sites More sharing options...
Christian F. Posted September 11, 2012 Share Posted September 11, 2012 Add a little note about overwriting the resource variable, and I think we have a winner. Quote Link to comment https://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/#findComment-1376927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.