problem with eregi function in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harshilshah
Forum Newbie
Posts: 16
Joined: Fri Jul 17, 2009 5:13 am

problem with eregi function in PHP

Post by harshilshah »

here's my code

Note: I am using php 5.0.3

Code: Select all

class ArchiveExtractor {
 
 
  /**
 
    Extract Archive(TarGzip, Zip) based on file suffix
 
    @param string Archive file
    @param string extraction path
 
    @return array
 
  */
  function extractArchive($archFile, $extractPath=".") {
    echo "ARCH: ".$archFile."<br />ExtPath: $extractPath";
    $result="";
    
    if(eregi("tar|gz|tar.gz|tgz",$archFile)) {
      $result=$this->extractTarGzip($archFile,$extractPath);
    }
    else if(eregi("zip",$archFile)) {
      $result=$this->extractZip($archFile,$extractPath);
    }
    
    /* Return result */
    return $result;
  }
 
  /**
 
    TarGzip file extractor function
    
    @param string Archive file
    @param string extraction path
    
    @return string
    
  */
  function extractTarGzip($archFile, $extractPath=".") {
    /* include TAR library */
    require_once 'pcltar.func.php';
    
    /* extract and return list of extracted files */
    return PclTarExtract($archFile,$extractPath);
  }
  
  
  /**
 
    Zip file extractor function
 
    @param string Archive file
    @param string extraction path
 
    @return array
 
  */
  function extractZip($archFile, $extractPath=".") {
    /* include Zip Library file */
    require 'pclzip.class.php';
    
    
    /* Extract */
    $zip=new PclZip($archFile);
    
    /* list of extracted files */
      return $zip->extract($extractPath);
  }
  
  /**
    Get Tar/Gzip archive's file list
    @param string
    @return array
  */
  function getTarGzipList($archFile) {
    /* include TAR library */
    require_once 'pcltar.func.php';
    
    /* return list */
    return PclTarList($archFile);
  }
  
  /**
    Get Zip archive's file list
    @param string
    @return array
  */
  function getZipList($archFile) {
    /* include Zip Library file */
    require 'pclzip.class.php';
 
 
    /* Extract */
    $zip=new PclZip($archFile);
 
    /* return */
    return $zip->listContent();
  }
  
  
}
?>
 
here's my error





Deprecated: Function eregi() is deprecated in C:\wamp\www\godnels\imagealbum\ArchiveExtractor.class.php on line 42

Deprecated: Function eregi() is deprecated in C:\wamp\www\godnels\imagealbum\ArchiveExtractor.class.php on line 45
album submitted
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: problem with eregi function in PHP

Post by JAB Creations »

Don't use eregi as it's been deprecated and won't be available in PHP6. I'm pretty sure you'll want to use preg_match.

Also your script doesn't look overly indepth though as a good practice when you do things like form verification you'll want to execute regular expressions as the last step of verification as it generates the most server load. So if you can catch a validation error (such as length) first then you'll be spared from creating unnecessary load (and thus poorer server performance). :wink:
harshilshah
Forum Newbie
Posts: 16
Joined: Fri Jul 17, 2009 5:13 am

Re: problem with eregi function in PHP

Post by harshilshah »

JAB Creations wrote:Don't use eregi as it's been deprecated and won't be available in PHP6. I'm pretty sure you'll want to use preg_match.

Also your script doesn't look overly indepth though as a good practice when you do things like form verification you'll want to execute regular expressions as the last step of verification as it generates the most server load. So if you can catch a validation error (such as length) first then you'll be spared from creating unnecessary load (and thus poorer server performance). :wink:
how do i use it in my case. i dont know how to use it.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: problem with eregi function in PHP

Post by Dynamis »

preg_match

That should answer all of your questions (there are examples if you scroll down) but if not let me know and I could give you another example.
harshilshah
Forum Newbie
Posts: 16
Joined: Fri Jul 17, 2009 5:13 am

Re: problem with eregi function in PHP

Post by harshilshah »

here's the code i used with preg_match function

Code: Select all

 function extractArchive($archFile, $extractPath=".") {
    echo "ARCH: ".$archFile."<br />ExtPath: $extractPath";
    $result="";
    
    if(preg_match("%tar%gz%tar.gz%tgz",$archFile)) {
      $result=$this->extractTarGzip($archFile,$extractPath);
    }
    else if(preg_match("%zip%",$archFile)) {
      $result=$this->extractZip($archFile,$extractPath);
    }
    
    /* Return result */
    return $result;
  }
here's the error i am getting. Please help me its urgent.
Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\wamp\www\godnels\imagealbum\ArchiveExtractor.class.php in line5
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: problem with eregi function in PHP

Post by McInfo »

In this case, it might be more appropriate to use pathinfo() and in_array() rather than regular expression functions.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 3:57 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: problem with eregi function in PHP

Post by pickle »

If you notice in all the examples, the patterns all start and end with the same character. That character is called the "delimiter". It looks like you've chosen "%" as your delimiter. Traditionally "/" is used, but "%" will work just as well.

Your first pattern is filled with multiple occurrences of "%". If you want them to be in your pattern as literal characters (ie, you want to match a percent sign & not have it treated as a delmiiter) then you need to escape it like this: "\%". Your error is being thrown because the regex engine sees the second occurrence of "%" as the closing delimiter, and tries to interpret the rest of your pattern as pattern modifiers, of which "g" is not valid.

If you're going to use regular expressions, I highly recommend reading through the Regex Crash Course Tutorial we've got.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply