View Full Version : Swedish chars becoming ?

04-03-2007, 03:37 PM
I have a small simple php page that basically does something like this:

$sendstring="new Array(";
$result = mysql_query("select output from xxx",$db) or die("Query sucks!");

while ($myrow=cl_mysql_fetch_array($result)) {

echo "$sendstring";

And when I just run that page the result comes out as intended with the correct line in the browser. (if I run only the PHP page)

But when I run it thru my AJAX influensed Javascript, all the Swedish chars becomes ? instead of , or .

Anyone got any idea why Javascript makes this look wierd?

04-03-2007, 10:56 PM
I solved it by doing this in the PHP code:

function cl_html_entity_encode($str){
return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);

And changing one of the last lines to:


Then added this function to my JavaScript:

function html_entity_decode(str) {
var ta=document.createElement("textarea");
return ta.value;

Then this further down:

eval("var d="+tmpstr);

So I basically encode them as HTML entities in PHP, then decode them in Javascript before I put the values into my dropdown box. And it works nicely.

Just wanted to share if anyone else had the same or similar problems.