【发布时间】:2015-04-30 01:30:37
【问题描述】:
我在修复这个旧的 PHP eregi 函数时遇到了问题,因为它使用了 IN 参数。 这是来自 Matthieu MARY 的验证码生成 class_log.php 的脚本
旧代码:
$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']++;
}
我尝试了这个,但不确定它是否正确?
$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
【问题讨论】:
-
preg_match("/$pattern/"); -
不,这不是因为您在分隔符
/之外添加了一个字符(空格)。更好的方法是重写模式以一次性测试两个条件。一个基本的教程会帮助你。
标签: php preg-match eregi