How to print a unicode string in PHP

I have this little 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 Laszlo Merton.

What am I doing wrong?

+2


a source to share


3 answers


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

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



echo "László Márton";

      

But it looks like you want to print a Javascript encoded sequence. OK. But you need to print well-formed javascript.

0


a source


Have you looked at the mbstring library in PHP?

This page shows you the basic handling of multibyte output lines.



Also, as stated in another answer, your encoding should be utf-8

0


a source


try using charset = utf-8 instead of utf8

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

0


a source







All Articles