【问题标题】:Compilation failed: invalid range in character class at offset 4编译失败:偏移量 4 处的字符类范围无效
【发布时间】:2019-09-19 03:08:58
【问题描述】:

我使用 CI_Minifier 并在更新我的 PHP 后遇到问题。

现在我在使用preg_match 函数时收到错误消息。

if (!preg_match("/^[\w-:]+$/", $tag)) { #error line
    $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
    if ($this->char === '<') {
        $this->link_nodes($node, false);

        return true;
    }

    if ($this->char==='>') {
        $node->_[HDOM_INFO_TEXT] .= '>';
    }
    $this->link_nodes($node, false);
    $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next

    return true;
}

错误是:

编译失败:偏移量 4 处的字符类范围无效

【问题讨论】:

  • 很有可能$this-&gt;doc的元素少于4个,但$this-&gt;pos等于4

标签: php codeigniter preg-match


【解决方案1】:

转义连字符:

if (!preg_match("/^[\w\-:]+$/", $tag)) { 

或者放在字符类的开头:

if (!preg_match("/^[-\w:]+$/", $tag)) { 

或在最后:

if (!preg_match("/^[\w:-]+$/", $tag)) { 

【讨论】:

  • @TomislavTomiNikolic:我很惊讶,它对我来说效果很好。
  • 太好了,用 \ 转义连字符后,它就像一个魅力。谢谢
  • 我想知道你是怎么想逃避连字符的?和我的大部分发现一样,这是偶然的吗?无论哪种方式 - 感谢您的经验,它为我节省了大量的人才和时间。这与 PHP 版本有关吗?我想知道..
  • @ScottFleming:这是一个通用错误。 invalid range in character class 得到了自我解释。可以肯定的是,总是转义字符类中的连字符。
猜你喜欢
  • 2020-03-20
  • 2020-02-18
  • 1970-01-01
  • 2022-11-22
  • 2014-11-30
  • 1970-01-01
  • 1970-01-01
  • 2020-01-28
  • 2014-11-24
相关资源
最近更新 更多