Reputation: 562
I have this problem where I converted a special character to be put on the URL as a parameter using Javascript Ajax request and then reads it to PHP. The character is "Ñ".
In my javascript I put the parameter as escape('PiÑa') and is converted to "Pi%D1a"
And when I read it in my php a diamond shape with a question mark is what will appear. Here is how I read it.
escape(message) // Message being the "Pi%D1a"
Like I said a weird character comes out that when I save it my database, postgreSQL, It gives out an error. How do I fix this?
Upvotes: 0
Views: 417
Reputation: 522005
D1
is the ISO-8859-1 ("Latin-1") encoded form of the "Ñ" character.
A "diamond shape with a question mark" (�) is the Unicode Replacement Character. Whenever you see one, it indicates that the browser/editor/whatever-is-interpreting-the-text is trying to interpret text as Unicode and is encountering a character that is not valid in the assumed Unicode encoding.
In other words, the character is actually Latin-1 encoded but you're telling the browser it's (likely) UTF-8 encoded. You have an encoding mismatch. Either tell the browser the right encoding via a Content-Type: text/html; charset=XXX
header, or convert the character from Latin-1 to UTF-8 before working with it.
Upvotes: 1
Reputation: 5903
Have you tried using urldecode($message)
?
%D1
is the URL encoded representation of Ñ.
Upvotes: 0