I got a hard time with accent (hey i'm french, nobody is perfect !) both problem in php and javascript.. here is the code :
in php :
$message = "";
$message .= "Bonjour!". "\r\n";
$message .= "Je désire m'inscrire à la liste d'envoi pour recevoir le bulletin de la Fondation Martin-Matte par courriel.". "\r\n";
$message .= "Merci"."\r\n";
$message = utf8_encode($message);
the encode function produce :
Bonjour!, Je désire ......
not good !
HOW to encode properly a string with accent ?
and in javascript : alert ("l'adresse de courriel : "+ email +" est bien ajouté à la liste d'envoit, merci");
produce a � caracter...
what should i do ???? help
The htmlspecialchars() function converts some predefined characters to HTML entities.
php $transliterator = Transliterator::createFromRules(':: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD); $test = ['abcd', 'èe', '€', 'àòùìéëü', 'àòùìéëü', 'tiësto']; foreach($test as $e) { $normalized = $transliterator->transliterate($e); echo $e.
The htmlspecialchars() function converts special characters into HTML entities. It is the in-built function of PHP, which converts all pre-defined characters to the HTML entities.
désire
is caused by unicode (UTF-8) characters being displayed as ANSI. The � character is caused by ANSI characters (above 127) being displayed as UTF-8.
When your PHP outputs UTF-8 character, you should also send a Content-Encoding header to notify the client that the data is UTF-8. It is recommended to output this encoding in the heading of your HTML file as well.
I think you can save javascript files as UTF-8 without problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With