?
Solved

Encoding and utf8_encode

Posted on 2007-12-01
7
Medium Priority
?
1,048 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
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!

 
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 2000 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

764 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