Results 1 to 4 of 4

Thread: formatting gets lost - php -> xml

  1. #1
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default formatting gets lost - php -> xml

    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?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    The formating looks correct in my xml file.
    each line ends with a
    Code:
    &.#.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;
    }
    ?>
    Last edited by I am Abby; 05-18-2010 at 09:25 PM. Reason: missing code

  4. #4
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Found the solution to the problem. nl2br()

    all I did was change
    Code:
    <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
    Code:
    <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
    )
    }
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •