I would like to inform the user what character does not meet the regex.
But when I try to print it out to the screen it renders as a triangle with a question mark on it.
Here is my code…
$matches = array();
$pattern = '"[^@?0¡Pp£_!1AQaq\$F\"2RBbr3¥G#\s\.\,\:\'3CScsè?¤4DTdtéO%5EUeuù?&6FVfvì?7GWgwòS\(8HXhxÇT\)9IYiy?\*:JZjzØ\+\;KÄkäøÆ\,\<LÖlöæ\-\=MÑmñÅ\.\>NÜnüåÉ\/\?O§oà\{\}]"';
$text = "Flight Vol {FN} vol est retardé d'au moins 1 heure, s'il vous plaît consulter les écrans de l'aéroport pour les mises à jour. Service à la clientèle de AIRLINE";
if(preg_match($pattern, $text, $matches)){
$output = '<p>This Text contains invalid character(s) ';
$output .= '<span style="color:#000; border-bottom:1px dashed #F33; padding:0px 5px 0px 5px; "><strong>'.implode(" ",$matches).'</strong></span>';
$output .= ' is not allowed.</p>';
$output .= "<p><strong>".$text."</strong></p><br />";
print $output;
}
I am thinking it is something to do with Latin encoding or UTF-8 but I use UTF-8 in the rest of the site. What is the best way to render the characters inside the $matches array, so the user can correct their text?
Use the UTF-8 regex modifier: