Solved

Php file utf 8 problem?

Posted on 2007-12-06
2
629 Views
Last Modified: 2008-02-01
Ok,
 I have in my mysql database utf 8  and bunch of characters what are not supported by PHP.
I wanted to make some language file in my script and I cant write some special chars. Wenn I save the file it looks file, wenn I open it , it looks screwed up.
For example:

$language]['Austria'] = "Österreich";

Can I write directly in some php variable chars like üäö , I don want to write this ü ä ö

So my question is, is possible to write some php characters in php file directly?
0
Comment
Question by:galic1987
2 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20419405
Make sure that you page that displays the characters has the correct encoding.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Also if you are opening the file with fopen use binary mode.

E.g

fopen("file.txt","rb");
0
 
LVL 19

Accepted Solution

by:
SteveH_UK earned 500 total points
ID: 20419426
PHP code does not support Unicode characters natively (at least not in PHP <= 5).

However, you could preload text from a file into an array and treat it as binary.

If you do this, make sure you don't get caught out by Byte-Order-Marks (BOMs) at the beginning of the files.

We did this to support a country list.  I've used Unicode extensively in PHP 4, with custom code.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question