jiveturkey Posted May 25, 2007 Share Posted May 25, 2007 Hello All First post here, so sorry if this is a common request. I am trying to build a website which will have pages that include long bits of descriptive text such as describing the history of places of interest in Japan. In the database I have set this up as a text type column. If I want to format the various paragraphs in the text as html paragraphs how should I go about it? It is possible to break up a long piece of text using PHP (via a loop) and add <p> tags or should I add the p tags to the data inserted into the data base. I don't really like the last option as its not re-useable. The other option is to make a separate table for the text and split this into paragraphs but this idea seems like a non-starter for me. I hope you can understand this - and if you can I'd appreciate any help J Quote Link to comment Share on other sites More sharing options...
Illusion Posted May 25, 2007 Share Posted May 25, 2007 Make use of strip_tags function in PHP. Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted May 25, 2007 Share Posted May 25, 2007 Store paragraphs normally like a text file with paragraphs seperated by two newlines and then output the paragraph something like this: <?php $result = mysql_query("SELECT history FROM repository WHERE id = 1"); if (mysql_num_rows($result) && (list($record['history']) = mysql_fetch_row($result)) { $record['history'] = "<P>" . str_replace("\n\n", "</P><P>", $record['history']) . "</P>"; print $record['history']; } ?> The above would not be appropriate for complex formatting, like colours and type styles... user defined code blocks like forums use may be more appropriate if more complex formatting is required. Quote Link to comment Share on other sites More sharing options...
fenway Posted May 30, 2007 Share Posted May 30, 2007 Yup, don't store html in a DB, especially for line breaks. I've seen a PHP function for interconversion before... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.