Errors concerning depreciated eregi

This is the error i am receiving

Deprecated: Function eregi() is deprecated in /home/socia125/public_html/profile.php on                  
line231

This is my code

// Loop through the array of user agents and matching operating systems
   foreach($OSList as $CurrOS=>$Match) {
    // Find a match
    if (eregi($Match, $agent)) {
            break;

any help is appreciated

Answers


Use preg_match instead of eregi.

But it seems like all it does is searching for a string, so you might be able to use stripos instead.

// Loop through the array of user agents and matching operating systems
   foreach($OSList as $CurrOS=>$Match) {
    // Find a match
    if (stripos($Match, $agent) !== FALSE ) {
            break;

I can't guarantee that it works as it should, since we don't see all of the code (especially contents and example values of $Match and $agent)


Well, as the manual quotes,

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Use preg_match() instead. Be a bit careful though, because you cannot convert your search pattern 1:1 from eregi to preg_match().

Example to show the difference:

$t = "this is a test...";
if (preg_match("/test/i", $t)) echo "match!";
if (eregi('test', $t)) echo "match!";

There is a whole chapter in the php manual dedicated to the PCRE syntax.

But if you're just simply trying to find a string, use something like strstr or stristr, those are faster and easier to use.


eregi() is deprecated as of 5.3. You may ignore this as it is just a warning.

I would recommend to use preg_match() instead.

See the link here


Need Your Help

Building a C# Web API - REST

c# asp.net

I am about to start a project in C#. I've never used c# and I was hoping I could get some implementation advice before I make a silly mistake and go down the wrong path.

NSFetchedResultsController not calling didChangeObject

ios objective-c nsfetchedresultscontroller magicalrecord

I should start by saying that this all works great when I deploy a debug build to my device directly from xcode. I only see this problem when I build a signed release IPA.