menardmam
menardmam

Reputation: 9986

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

Upvotes: 5

Views: 3259

Answers (2)

user1691434
user1691434

Reputation:

To convert ANSI to UTF-8 or UTF-8 to ANSI, open the file with Notepad and use Save as. this opens a box where it's possible to choose UTF-8 or ANSI.

I did it and my problem was solved in a second.

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

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.

Upvotes: 5

Related Questions