I use a PHP file to create an XML for loading from SQL to Flash. Unfortunately all my linebreaks are recognized as being double, which, ofsourse, they aren’t. I’ve searched the forum for an answer, but I could not find a solution. Only to the same problem where the XML isn’t created by a PHP like mine is.
Here’s (part of) my script:
echo '<?xml version="1.0" encoding="UTF-8"?>' . $nl;
echo '<ROOT>' . $nl;
while($r = mysql_fetch_array($result)) {
echo '<pagina>' . $nl;
echo '<pageId>' . stripslashes($r['pageId']) . '</pageId>' . $nl;
echo '<pageTitle>' . stripslashes($r['pageTitle']) . '</pageTitle>' . $nl;
echo '<pageText><![CDATA[' . stripslashes(str_replace('
','<BR>',$r['pageText'])) . ']]></pageText>' . $nl;
echo '</pagina>'. $nl;
}
echo '</ROOT>' . $nl;
The problem arises in the CDATA part, where the actual text is loaded. I’ve tried to add nl2br(), which works, sort of… It removes a break in one part but adds another somewhere else, leaving me with a very odd looking piece of text. I’ve also tries a str_replace to get rid of any
or \r in the tekst, but it doesn’t seem to find anything to replace.
If anyone has any further tips, I’d be very happy to hear them!
[edit]Nevermind, I figured it out. I did need to use a str_replace, but I had a slight error in it…[/edit]