xp-lang/php-pattern-operator

v0.2.0 2024-03-24 13:08 UTC

This package is auto-updated.

Last update: 2024-08-24 13:56:37 UTC


README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

这是一个为XP 编译器提供的插件,该插件为PHP语言添加了一个中缀运算符~

示例

模式运算符将以下表达式视为正则表达式,并返回其生成的匹配项

if ($greeting ~ '/^H[ea]llo/') {
  // Matches!
}

if ($matches= $greeting ~ '/^H[ea]llo/') {
  // Work with $matches
}

模式将被传递到preg_match,因此上述代码等同于以下代码

if (preg_match($greeting, '/^H[ea]llo/')) {
  // Matches!
}

if (preg_match($greeting, '/^H[ea]llo/', $matches)) {
  // Work with $matches
}

安装

将XP编译器安装到您的项目中后,还需要包含此插件。

$ composer require xp-framework/compiler
# ...

$ composer require xp-lang/php-pattern-operator
# ...

无需进行其他操作。

另请参阅