Log in

View Full Version : If Function eregi() is deprecated



Webiter
09-09-2011, 02:04 PM
Seeking to get a newsletter faciliity working. Before I move to a production server I would wish to eliminate the depreciated item that I am picking up in WAMP.

I am being advised as follows on line 146.

Deprecated: Function eregi() is deprecated in C:\wamp\www\newsletter\wespa_php_newsletter_v3\inc\csvfile.php on line 146

Line 146 is identified in the code below -




function open( $mode )
// opens the data source
{
if ( ! $this->handle = fopen( $this->name, $mode ) )
{
return false;
}
else
{
// lock file if opened for write mode
Line 146 = if ( eregi( "a|w|\+", $mode ) )
{ flock( $this->handle, 2); }

$this->eol = feof( $this->handle );
return true;
}
}

How should I apply the 'preg_match' to update this line of the code? :o

jscheuer1
09-09-2011, 02:22 PM
function open( $mode )
// opens the data source
{
if ( ! $this->handle = fopen( $this->name, $mode ) )
{
return false;
}
else
{
// lock file if opened for write mode
if ( preg_match( '/a|w|\+/i', $mode ) )
{ flock( $this->handle, 2); }

$this->eol = feof( $this->handle );
return true;
}
}

Note: preg_match is not case insensitive as was eregi, hence the added i switch:


preg_match( '/a|w|\+/i', $mode )

The only other difference of note here is that with preg_match delimiters must be included within the quoted string which represents the regular expression being used:


preg_match( '/a|w|\+/i', $mode )

I switched from double quotes to single quotes as they're generally safer if not required to resolve variables within them, which they are not here.

For more info, see:

http://us3.php.net/manual/en/function.preg-match.php

Webiter
09-09-2011, 07:48 PM
Thanks, Your revison worked a treat. :)