Using UTF-8 encoding in php files/output HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Using UTF-8 encoding in php files/output HTML

Post by mbaroz »

Hi
Im trying to use <meta....Encoding="utf-8"> while my php vars use hebrew characters and i get Scrumbled japaneese font instead of HEBREW
When i use encoding="windows-1255" it is ok ofcourse
But i would like to work unicode.
This issue occures when i use text from vars and DB (not static in an html pure code)
My server is runing IIS 6 . Windows 2003

Where can i change / fx configuration to have this problem fixed ?
Thanks ,
Moshe
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Not sure what you are saying exactly, but I work with unicode/php a lot.

A common way to store text is in language files. eg. mysitetext-he.php, mysitetext-en.php etc.

Then you save your text in vars in those files, and save the files encoded with UTF-8 but without the BOM (Byte Order Mark) at the beggining. Then on a webpage you can include the language file of the user's choice and print the text. Make sense? Besure to set your webpage charset to utf-8. Also, you must have some type of Hebrew Unicode font installed, simply a Hebrew font is not enough, must be a unicode font.

To remove the BOM from a UTF-8 encoded php file, you can use the DOS Edit command, Yudit, EmEditor ... to name a few.
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Unicode

Post by mbaroz »

Hi
My problem is not the file itself, i have the vars in a lang file (heb.inc.php/eng.inc.php) , the problem is that when the browser encodes the output it sends it as Japaneese like , instead of Hebrew.
here is an example:
<html>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<?
$mytext="שלום לכולם";
print $mytext;
?>
</html>

this output strange characters ...
Thanks Moshe
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Pyrite wrote:Also, you must have some type of Hebrew Unicode font installed, simply a Hebrew font is not enough, must be a unicode font.
Have you done this?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Sometimes your webserver might not be setup to handle hebrew fonts, an easy way around fixing it is instead to force a utf-8 header to the browser, so before any output you can do.

Code: Select all

header('Content-Type: text/html; charset=utf-8');
Post Reply