I'm trying to extract special characters (from a predefined pattern) from a string, but when this string starts with an inverted question mark, "match" returns the first two characters, including non-special ones. For instance:.
$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; }
In this example, the function returns "¿h", but expected "¿" ... I can not understand the problem ...
jprog source share