Results 1 to 11 of 11

Thread: Preserving formatting (mySQL and PHP)

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Preserving formatting (mySQL and PHP)

    Here's the go,
    In a mysql database, i have stored code snippets.

    however when i print out what is in the field (the code snippet field)

    It prints out with no carriage returns, i.e.

    Code:
    'This code is for disabling resizing'Written by Matthew GatesOption Explicit
    How do i fix that?

    this is my current code
    PHP Code:
                  $title mysql_result ($result0"title"); //Get the title
                
    $type mysql_result ($result0"type");
                
    $description mysql_result ($result0"description");
                
    $code mysql_result ($result0"code");
                echo 
    "<center>$title</center><br>$vb<br>$description<br><br>$code"

  2. #2

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Fixed that, new problem

    I solved that with:
    PHP Code:
                $title mysql_result ($result0"title"); //Get the title
                
    $type mysql_result ($result0"type");
                
    $description mysql_result ($result0"description");
                
    $code nl2br(mysql_result ($result0"code"));
                echo 
    "<center>$title</center><br>$vb<br>$description<br><br>$code"
    Is there any way i can preserve tabs?

  3. #3
    scoutt
    Guest
    what is the field type in Mysql for that categorie? like varchar or something

  4. #4

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    text

  5. #5
    scoutt
    Guest
    if it is text then I don't see why it won't. I use text and it does preserve the tabs and breaks. are you stripping the htmlcharacters from it?

  6. #6

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

  7. #7
    scoutt
    Guest
    ahhh I know why. I put mine in a text area and you aren't. the reason you don't is becasue the browser doesn't let it. you should insert the htmlspecial characters into it. like exchange the break for a <br> and exchange the so many spaces & nbsp; and make it so many spaces.

    I ran into this but decided to put the code in a textarea and make it readonly so I can keep the formatting.

  8. #8

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Thanks man, i'll try htmspecial'charring' it...

    I wonder how John does it

  9. #9

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Have a look at it now, -> no such luck

    Still preserves line spacing, but can't get proper tabs.

    Myphpadmin can in a textbox

    I got it working in a scrolling text box, but i wanted to color code it i'll see if John replies

  10. #10
    scoutt
    Guest
    yeah let me know, maybe he uses the <pre> tags. still let me know, might be something to keep in mind.

  11. #11

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yeah that worked.

    Thanks man

    Now i just need to get the [vbcode ] formatting code off john...

Posting Permissions

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



Click Here to Expand Forum to Full Width