Format preserving

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raaman rai
    New Member
    • Oct 2007
    • 114

    Format preserving

    if we are to have news management system in php for our site, how can we preserve the format of the contents. I mean a news can be long enough to have many paragraphs, and sometimes we may need to insert bullets and numbering, and so on..... In this case, when we add news to database, how is the contents given the same format as it is entered so that when we fetch it, the contents are displayed in the same format as entered .
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    A very good example for you is Wikipedia. Open any page on it, and click somewhere on edit. See how are they save the formatting. Its really database friendly (consuming less bytes).

    (link)

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      If you save it into the database exactly as it was typed, including all white-space characters like the new-line char and the tab char you can print it in a <pre> tag or in a div with the 'white-space: pre' style set.
      That way all the paragraphs and such will be preserved.

      For numbering and bullets and other sort of formatting, you could try using BBCode.

      Comment

      • raaman rai
        New Member
        • Oct 2007
        • 114

        #4
        thanks buddy, it was great but i must tell you that i couldnot configure the BBCode Parser. Infact i am using WAMP5 version 2 and i think i did install PEAR with the assistance from some tutorials. But unfortunately i couldnot configure the BBCode Parser as i could not find a proper help or tutorials. So, would you mind helping me how to do it?

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          I'm not sure about the PEAR package. I never really got into that stuff.

          But as far as I know, you should only have to install it, by typing something like this into a cmd.exe window:
          Code:
           pear install HTML_BBCodeParser
          And then you should be able to use it, like:
          [code=php]
          <?php
          // Load and create object
          require_once('H TML/BBCodeParser.ph p');
          $parser = new HTML_BBCodePars er();

          // Parse some text
          $parser->setText($_PO ST['SomeString']);
          $parser->parse();

          // Print the parsed text
          echo $parser->getParsed();
          ?>
          [/code]

          Comment

          • raaman rai
            New Member
            • Oct 2007
            • 114

            #6
            hey you made me fly, it was awesome as it worked. Thanks ya man but i am not sure if this setup is managed by the ISP itself (who is hosting the web) or it needs to be done by ourselves. Please do me another favour by enlighting me in this issue.

            Comment

            Working...