tags:

views:

108

answers:

3

I have this small script:

<?
header('Content-Type: text/javascript; charset=utf-8');
$s="L\u00e1szl\u00f3 M\u00e1rton";
echo $s;
?>

The browser displays "L\u00e1szl\u00f3 M\u00e1rton"

and it should display László Márton.

What I am doing wrong?

A: 

Have you taken a look at the mbstring library in PHP?

This page shows you some basic multibyte output string handling.

Also, as pointed out in another answer, your charset should be utf-8

webdestroya
What to look for there?
Pentium10
Ok, I updated the answer.
webdestroya
It doesn't help. I added mb_http_output("UTF-8");ob_start("mb_output_handler"); but I get no change.
Pentium10
A: 

try using charset=utf-8 instead of utf8

here's a helpful resource for php charset problems: http://www.phpwact.org/php/i18n/charsets

Keith
I corrected this but still nothing.
Pentium10
A: 

Well you have to understand the difference between server, browser and javascript.

To answer your question "How to print unicode string in PHP" is simple: just print it:

echo "László Márton";

But it seems you want to print Javascript-encoded sequence. OK. But you need to print well formed javascript then.

Col. Shrapnel
So how do I do this?
Pentium10
@Pentium how to do what? Javascript code? Just write it. I have no idea what javascript code you want. But string "László Márton" doesn't looks like javascript code
Col. Shrapnel
This is from a JSON response, I don't have javascript, only PHP or Java.
Pentium10
@Pentium it is not JSON response either. You have to learn how to encode json responses properly. And I don't have java, only PHP or Javascript.
Col. Shrapnel