gpt4 book ai didi

php - 正则表达式字边界在某些服务器上的 utf8 中不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 20:53:51 25 4
gpt4 key购买 nike

我有一个奇怪的问题。考虑这个简短的代码:

<?php
$reg = '/(?<!\pL)(test)(?!\pL)/u';
$text='This is a test text';
$replace = 'test_replaced';

$newtext = preg_replace($reg, $replace, $text);

echo "Error: ".preg_last_error()."\nResult: ".$newtext."\n";

?>

在某些服务器上,UTF8 边界匹配不起作用。我明白了

Error: 0
Result:

在大多数服务器上一切正常:

Error: 0
Result: This is a test_replaced text

当我使用 \b 而不是代码时,字边界似乎有问题。

两个服务器都使用 php 5.2.13。任何线索可能是错误的以及如何解决它?

最佳答案

评论here似乎暗示PCRE需要用--enable-unicode-properties编译。

关于php - 正则表达式字边界在某些服务器上的 utf8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4781898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com