Solved

Php file utf 8 problem?

Posted on 2007-12-06
2
626 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now