Solved

Php file utf 8 problem?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

13 Experts available now in Live!

Get 1:1 Help Now