phppreg-matcheregi

Replace old eregi function PHP


I'm having problems to fix this old PHP eregi funxtion becouse it uses IN parameter.. It's script for captcha generation class_log.php from Matthieu MARY

old code:

$sMotif = "--$sIN ([a-zA-Z0-9]{3,4},)*([a-zA-Z0-9]{3,4}){1}";
if ((eregi("$sMotif ",$this->sParam))||(eregi("$sMotif$",$this->sParam))){
    $this->aParam['bExtension'] = TRUE;
    $this->aParam['aExtension'] = $this->_PARAM_get_extension($sIN);
    $this->aParam['inExtension'] = ($sIN=='e');
    $this->aParam['iParameters']++;
}

I try with this, but not sure is it correct?

$sMotif = "/--$sIN ([a-zA-Z0-9]{3,4},)*([a-zA-Z0-9]{3,4}){1}/i";
if ((preg_match("$sMotif ",$this->sParam))||(eregi("$sMotif$",$this->sParam))){
    $this->aParam['bExtension'] = TRUE;
    $this->aParam['aExtension'] = $this->_PARAM_get_extension($sIN);
    $this->aParam['inExtension'] = ($sIN=='e');
    $this->aParam['iParameters']++;
}

tnx


Solution

  • Here is the way I'd do the job:

    $sMotif = "/--$sIN ([a-zA-Z0-9]{3,4},)*([a-zA-Z0-9]{3,4}) ?/";
    if ( preg_match($sMotif,$this->sParam)) {