View Full Version : formatting gets lost - php -> xml
I am Abby
05-18-2010, 02:57 PM
I've created php pages to get info and send it to my xml. Then created pages to view the information but it looses the formatting somewhere in the process. How do I keep my formatting?
djr33
05-18-2010, 05:10 PM
From that little info, it's really hard to tell.
What is formatting? HTML markup?
Perhaps the HTML is getting parsed as XML.
You should escape it before saving it and unescape it when loading it.
> becomes &gr; becomes >, and so forth.
I am Abby
05-18-2010, 07:36 PM
The formating looks correct in my xml file.
each line ends with a
&.#.1.3.;
(I had to use dots between the items cause it kept disapearing...so remove the dots)
isn't that the code for the end of a line?
On the page I only want to show the last message (if they want to see others they will need to go to another page to view old items) so I use the following code. I even ripped the code and used it in on an otherwise empty page to make sure none of my other code is screwing with it...yet, I get the same results. All the text runs together like one big paragraph.
<body>
<?php
$file = 'xml/messages.xml';
$xml = simplexml_load_file($file);
$i = count($xml_>messages)-1;
for($x=$i;$x>=0;$x--)
{
echo
$xml->messages[$x]->title.'<br />'
$xml->messages[$x]->author.'<br />'
$xml->messages[$x]->message;
break;
}
?>
I am Abby
05-19-2010, 02:38 PM
Found the solution to the problem. nl2br()
all I did was change
<body>
<?php
$file = 'xml/messages.xml';
$xml = simplexml_load_file($file);
$i = count($xml_>messages)-1;
for($x=$i;$x>=0;$x--)
{
echo
$xml->messages[$x]->title.'<br />'
$xml->messages[$x]->author.'<br />'
$xml->messages[$x]->message;
break;
}
?>
into
<body>
<?php
$file = 'xml/messages.xml';
$xml = simplexml_load_file($file);
$i = count($xml_>messages)-1;
for($x=$i;$x>=0;$x--)
{
echo
nl2br('
.$xml->messages[$x]->title.'<br />'
$xml->messages[$x]->author.'<br />'
$xml->messages[$x]->message, false
)
}
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.