开发者

How to print unicode string in PHP

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?


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.


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


try using charset=utf-8 instead of utf8

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜