gpt4 book ai didi

php - 为什么 preg_match_all 强制我提供第三个可选参数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:34 25 4
gpt4 key购买 nike

<分区>

我正在计算 $text 中一些特殊字符的数量(如欧元符号),使用 preg_match_all 和这个正则表达式:

preg_match_all('/[\[|\]|€\{|}|\\|\^|\||~]/u', $text);

出于某种奇怪的原因,PHP 要求我提供第三个参数。但根据 documentation of preg_match_all 它应该是可选的:

Warning: preg_match_all() expects at least 3 parameters, 2 given.

如果我提供 PREG_PATTERN_ORDER(甚至不知道我为什么要这样做),我会得到:

Cannot pass parameter 3 by reference.

那么,我的代码有什么问题?如果需要,这里是整个函数:

public function getMessageCount($text)
{
$specials = preg_match_all('/[\[|\]|€\{|}|\\|\^|\||~]/u', $text)
$characters = strlen($text) + $specials;

if(in_array(strtolower($this->method), self::$classic_plans)) :

if($characters >= 0 && $characters <= 160) return 1;
if($characters >= 161 && $characters <= 306) return 2;
if($characters >= 307 && $characters <= 459) return 3;
if($characters >= 460 && $characters <= 612) return 4;

return 5;

endif;

if(in_array(strtolower($this->method), self::$basic_plans)) :

if($characters >= 0 && $characters <= 160) return 1;
if($characters >= 161 && $characters <= 312) return 2;
if($characters >= 313 && $characters <= 468) return 3;
if($characters >= 469 && $characters <= 624) return 4;
if($characters >= 625 && $characters <= 780) return 5;
if($characters >= 781 && $characters <= 936) return 6;
if($characters >= 937 && $characters <= 1092) return 7;
if($characters >= 1093 && $characters <= 1248) return 8;

return 9;

endif;

return in_array(strtolower($this->method), self::$zero_plans) ? 1 : null;
}

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