FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem with special char in MySQL and XML
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Problem with special char in MySQL and XML [message #174841 is a reply to message #174834] Wed, 13 July 2011 07:06 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 12/07/2011 22:02, Sarah escribió/wrote:
> Hi! I've a table UTF8_general_ci where I've symbols like:& è , à
> ' ...
>
> I've seen that when I try to generate an XML file (that works OK with
> other tables) I show this error:
>
>
> Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]:
> unterminated entity reference Pizza in /var/www/domain.com/xmlfeed.php
> on line 164
>
>
> In my PHP code I've something like this:
>
> $aaa->addChild('date', strip_tags(utf8_encode($row{'Date'})) );
> $aaa->addChild('title', strip_tags(utf8_encode($row{'Title'})) );

You are converting to UTF-8 some database info that's stored in UTF-8.
When, how and why do you convert it to ISO-8859-1?


Whatever, I've made some tests with SimpleXML and, curiously, it fails
to encode the "&" symbol :-? I looks like you need to do it yourself
either with htmlspecialchars() or strtr().

However, there's one more thing to take into account. Since you are
using strip_tags() I guess your input data is HTML. That means that it
can possibly contain its own HTML entities. Stripping HTML tags won't
convert entities back to regular characters and changing the "&" symbol
to "&" will convert stuff like "é" to "é" so you
will end up with plain text that contains HTML entities!

Since you are already using UTF-8 at some point, perhaps the only
reliable way to get rid of HTML entities is to use
mb_convert_encoding(). Full process would be:

$html = mb_convert_encoding($row['Title'], 'UTF-8', 'HTML-ENTITIES');
$text = strip_tags($html);
$simplexml_input = strtr(text , array('&' => '&'));




--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: xml rpc request with mynewsletter builder
Next Topic: how to implement AJAX to html
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 16:24:56 GMT 2024

Total time taken to generate the page: 0.04042 seconds