views:

41

answers:

3

Please i have asked this question before, hopin to get responses this time

I created a simple comment wall that submits using ajax.

Using javascript i collect user input:

var sharetxt =  encodeURIComponent(document.getElementById("cw_share_txt").value);

then pass it to a php page, on the php page, i collect the passed data:

$text=nl2br(htmlentities(trim(utf8_decode($_POST["txt"]))));

Encoding of the php page above:

header("Content-Type: text/xml; charset=utf-8");

My problem is that

  1. the wall doesnt still support multi languages (displays as ???? and causes my xml not to work)

  2. i still problems with some special characters (displays as � or ?)

What am i not doing right? please assist

+1  A: 
  1. Try to not utf8_decode
  2. Try using: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the header of the page to display characters correctly
Zsolti
i have removed the utf_decode, yet it doesnt display correctly. on the php page where d processing occurs, i set a header setting the charset to utf8: header("Content-Type: text/xml; charset=utf-8");. on the html page where i collect the data i set the charset like: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />. pls, Do u have any other clue?
Ogugua Belonwu
A: 

That looks like a classic case of mis-encoding.

I don't think you need the call to utf8_decode(). Since the source page is already declared as UTF-8 then the posted data is UTF-8 and you should a) leave it UTF-8 and b) make sure you declare the target page as UTF-8.

(Also, try in other browsers. IE has a reputation for guessing character sets badly, but (for example) I know Opera gets defensive and submits HTML entities if it can't match the character sets. That might help give you an idea of what is really wrong!)

staticsan
i have removed the utf_decode, yet it doesnt display correctly. on the php page where d processing occurs, i set a header setting the charset to utf8: header("Content-Type: text/xml; charset=utf-8");. on the html page where i collect the data i set the charset like: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />. Do u have any other clue?
Ogugua Belonwu
They should both do the same thing. Look in the browser's information page (for both pages) to see if it has set the right character set. Check if the target pages displays right if you force the browser to UTF8.
staticsan
it seems all my pages are utf8
Ogugua Belonwu
There is *something* that is not recognising your text as UTF8 and is re-encoding it as if it were something else, probably ISO-8859-1. You need to be creative in your testing and debugging to test smaller pieces of it. Check what the JS is encoding. Look at what the AJAX call thinks it is sending. Look at what the web server is actually receiving. Look at what the PHP is getting. Look at what it is doing to what it is getting - at as many steps as you can break it apart to. Without the environment and codebase in front of me, that's all I can suggest.
staticsan
A: 

And also, try to change the encoding of the document. I had the same problem as you and I changed the meta charset and the document encoding, works like a charm.

hellozimi
which of the charset do i change? the html page charset or the php header charset? and what do i change it to?
Ogugua Belonwu
I'm from Sweden, and as the page was in swedish I changed the document charset to ISO-8851-1 (Latin 1).
hellozimi
Oh, sorry. Didn't answer the question. I changed both files. Because if one is Latin 1 and the other is utf-8 it will be difference in the character coding.
hellozimi