I'm counting the number of some special characters (like euro symbol) in $text
, using preg_match_all
and this regular expression:
preg_match_all('/[\[|\]|€\{|}|\\|\^|\||~]/u', $text);
For some strange reason PHP asks me for a third parameter. But it's supposed to be optional as per documentation of preg_match_all:
Warning: preg_match_all() expects at least 3 parameters, 2 given.
If i provide PREG_PATTERN_ORDER
(even don't know why should i) i get:
Cannot pass parameter 3 by reference.
So, what's wrong with my code? Here is the whole function if needed:
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;
}