【问题标题】:Replace old eregi function PHP替换旧的eregi函数PHP
【发布时间】: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


【解决方案1】:

这是我的工作方式:

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

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 1970-01-01
    • 2020-05-15
    • 2014-12-07
    • 2017-07-24
    • 2013-02-09
    • 2021-11-20
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多