Solved

Encoding and utf8_encode

Posted on 2007-12-01
7
1,022 Views
Last Modified: 2013-12-13
I'm using Php to read an xml data file and after using fread I'm using utf8_encode to encode the data. The problem is when the data is printed in the browser there are unwanted characters
eg: Â",  Â, ­­Ã²Ã¥Ã°Ã¨Ã®Ã°ÃÃ, Ãðîçîðöè:, é, etc

What is the correct way of haddling this problem please?
0
Comment
Question by:ncw
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20388021
whats the encoding of the xml ?
whats the encoding of the page you are outputting the xml ?
0
 
LVL 1

Author Comment

by:ncw
ID: 20388049
I don't have much understanding of encoding but Textpad says the raw xml data has a code set of ANSI in the document properties. In IE6 under View -> Encoding I see Auto-Select ticked and Western European (Windows) is selected. If I change it to Unicode (UTF-8) then it looks a little better, but the  is replaced with a small outlined square box.

I think I need it to be compatible with the default Western European encoding.
0
 
LVL 1

Author Comment

by:ncw
ID: 20388095
The data file has come from Bulgaria and is being read in the UK, maybe the data should be encoded in Bulgaria at source?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 20

Expert Comment

by:steelseth12
ID: 20388119
The xml file should have the encoding in the document declaration.
e.g
<?xml version="1.0" encoding="utf-8"?>

also in your html put

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

if you already have a content type page change the character set to utf-8 ....

if the xml is also utf-8 then that should do the trick.

if its not then look at <?xml version="1.0" encoding=character_set_here"?> and tell what it is so we can convert it.
0
 
LVL 1

Author Comment

by:ncw
ID: 20388206
I provided an xml template with <?xml version="1.0" encoding="UTF-8" ?> in the first line, so I expected it to be encoded to ub=unicode but I believe it is ANSI. If I save it as utf-8 in Textpad and don't use utf8_encode then it looks ok. So either fread or utf8_encode is failing to handle the characters?

I will ask the supplier to output with utf-8 encoding, thanks.

0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20388332
utf8_encode encodes ISO-8859-1 encoded strings to utf8 if it is any other character set the you need to use iconv to change the encoding.
http://www.php.net/manual/en/function.iconv.php

0
 
LVL 1

Author Closing Comment

by:ncw
ID: 31412091
Thanks!
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

760 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