Dima
Dima

Reputation: 443

Combine different headers in PHP for non-English text

I am using PHP to display some foreign languages text.

  echo '<li> NO ENGLISH </li>';

to display a non English language that written in PHP I use:

header('Content-Type: text/html; charset=windows-1255');

But when I getting an posted variables from a form and try to echo them, it display trash. I noticed that setting the next header, fix it :

header('Content-Type: text/html; charset=UTF-8');

This header display it correctly, but fails display it for the first example.

How can I combine those different header settings in the same file.?

Upvotes: 1

Views: 105

Answers (1)

deceze
deceze

Reputation: 522442

You cannot mix encodings in a single document. The entire document must be in one coherent encoding with exactly one header set which denotes this encoding. If you receive differently encoded strings from several sources, convert them to one uniform encoding (preferably UTF-8) using mb_convert_encoding or iconv.

If your '<li> NO ENGLISH </li>' is simply hardcoded text saved in your source code file, save the file in a different encoding in your text editor. See UTF-8 all the way through and Handling Unicode Front To Back In A Web App.

Upvotes: 1

Related Questions