Solved

Encoding and utf8_encode

Posted on 2007-12-01
7
1,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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 …
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

726 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