我正在尝试从字符串中提取特殊字符(从预定义的模式中),但是当该字符串以倒置问号开头时,“匹配”会返回前两个字符,包括一个非特殊字符。例如。:
$string = '¿hola?';
$string2 = mb_convert_encoding($string, 'UTF-8');
$regex = mb_convert_encoding('/[a-zäáàëéèíìöóòúùñç]/', 'UTF-8');
if(preg_match($regex, $string2, $matches, PREG_OFFSET_CAPTURE))
{
//--> We pick the special characters into "$resultado1":
$resultado1 = mb_substr($string, 0, $matches[0][1],'UTF-8');
return $resultado1;
}
在此示例中,该函数返回“¿h”,但应为“¿”...我无法弄清楚问题...