Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accent in javascript and PHP

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

like image 728
menardmam Avatar asked Dec 13 '10 22:12

menardmam


People also ask

Why we use htmlspecialchars in php?

The htmlspecialchars() function converts some predefined characters to HTML entities.

How can I replace an accented character with a normal character in PHP?

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.

What is the use of HTML special characters?

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.


1 Answers

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.

like image 154
GolezTrol Avatar answered Sep 21 '22 00:09

GolezTrol