其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

php7.3正则表达式出错了[重复]

GG网络技术分享 2025-03-18 16:15 1


问题描述:

This question already has an answer here:

I am using simple_html_dom.inc.php for url extractor. The codes are working normaly without problem. But i am getting the following Warning from PHP7.3

Warning: preg_match(): Compilation failed: invalid range in character

class at offset 4 in 1387

You can see the error line in this link: Error Line 1387

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

$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;

}

Do you have a solution for this problem? Thanks in advance.

</div>

网友观点:

PHP 7.3 upgraded from PCRE to PCRE2. Which is much more strict on regular expressions. For example, you need to escape - between square brackets. And this is the problem in you regex.

Changing it to /^[\\w\\-:]+$/ should solve your problem.

一文看懂 PHP 7.3 更新

PHP 目前依旧是其它脚本语言强劲的竞争对手,这主要归功于其核心维护团队的快速更新。

自从 PHP 7.0 发布以来,社区见证了许多新特性的诞生,极大地改进了开发者在项目中应用 PHP 的方式。提高 PHP 应用的性能和安全性,是这些改进的主要目的。

PHP 最近实现了又一个里程碑 —— 发布 PHP 7.3。新版本带来了一些急需的更新。

在本文中,我将论述新推出的 PHP 7.3 特性 和更新。好消息是,你可以在你的测试服务器上自行安装新版本、查看新功能。但老生常谈,切勿在生产服务器上使用 RC 版本更新,可能会破坏你已经上线的应用。

以下是7.3版中引入的一些更新,与以前的版本相比,它们大大提高了 PHP 7.3 的性能

  • 灵活的 Heredoc 和 Nowdoc 语法
  • 函数调用时允许尾随逗号
  • JSON_THROW_ON_ERROR
  • PCRE2 迁移
  • list() 分配参考
  • is_countable 函数
  • array_key_first(), array_key_last()
  • Argon2 密码哈希增强功能
  • 弃用和删除 image2wbmp()
  • 弃用和删除不区分大小写的常量
  • 相同站点 Cookie
  • FPM 更新
  • 改进 Windows 下的文件删除

让我们逐一讨论上述的每一个更新。

灵活的 Heredoc 和 Nowdoc 语法

Heredoc 和 Nowdoc 语法能够在使用多行长字符串时起到很大帮助。它要求结束标识符应当为出现在新行的首个字符串。

标签:

提交需求或反馈

Demand feedback