Results 1 to 3 of 3

Thread: If Function eregi() is deprecated

  1. #1
    Join Date
    Aug 2011
    Location
    Rep Of Ireland
    Posts
    126
    Thanks
    24
    Thanked 3 Times in 1 Post

    Default If Function eregi() is deprecated

    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 -

    Code:
    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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    PHP Code:
    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->handle2); }

                
    $this->eol feof$this->handle );
                return 
    true;
            }
        } 
    Note: preg_match is not case insensitive as was eregi, hence the added i switch:

    Code:
    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:

    Code:
    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
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2011
    Location
    Rep Of Ireland
    Posts
    126
    Thanks
    24
    Thanked 3 Times in 1 Post

    Default

    Thanks, Your revison worked a treat.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •