News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthew Weir O'Phinney's Blog:
mbstring comes to the rescue
May 17, 2006 @ 05:49:23

Character encodings, especially when dealing with XML, in PHP can be a pain to say the least. Matthew Weir O'Phinney found this out first-hand when a script he was working with had a mixed character set in one of its strings, giving the XML parser in the SimpleXML functionality problems.

I tried a number of solutions, hoping actually to automate it via mbstring INI settings; these schemes all failed. iconv didn't work properly. The only thing that did work was to convert the encoding to latin1 -- but this wreaked havoc with actual UTF-8 characters.

Then, through a series of trial-and-error, all-or-nothing shots, I stumbled on a simple solution.

The discovery was to detect the encoding of the string itself (not really the content) and convert eveything in it to that encoding. How, you might ask? With the handy mb_detect_encoding and mb_convert_encoding functions. Of course, this functionality has to be compiled into PHP, but it's well worth it if it's exactly what you need.

0 comments voice your opinion now!
mbstring xml simplexml encoding utf-8 detect convert mbstring xml simplexml encoding utf-8 detect convert


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Building a Multilingual PHP Website

Jim Plush\'s Blog: My-Bic version 0.6 Released

PHPBuilder.com: The ABC's of PHP - Part 10 - The Final Installment (XML & Regex)

PHPBuilder.com: Using XML - A PHP Developer\'s Primer

PHPBuilder.com: Book Review: Pro PHP, XML and Web Services


Community Events





Don't see your event here?
Let us know!


experience developer laravel refactor opinion symfony2 unittest podcast series introduction community testing threedevsandamaybe code install release list interview language framework

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework