Forum Moderators: coopster

Message Too Old, No Replies

Displaying Formatted Content

         

kkonline

3:09 am on Nov 2, 2007 (gmt 0)

10+ Year Member



I am working on a article management system (to store data in database and retrieve and show it)

I use a form structure to submit the data into database.
It has a field called "content" which has textarea type of input.
When i enter few paragraphs

for example the content entered is
---content entered----
Basically you will want to run a PHP script file in specific intervals. Suppose you want to execute a php file called maintanence.php every one hour. This is what you do :-

The CRON Command is in the Following Format

CODE

[ Minute - Hour - Day - Month - Weekday ] - Command

The COMMAND, can be broken down in
---content entered----

It it stored as it is in the db. Next when i display the content I donot get the formated content. It shows just a continuous data without and formatting.

-----displayed data-----
Basically you will want to run a PHP script file in specific intervals. Suppose you want to execute a php file called maintanence.php every one hour. This is what you do :-The CRON Command is in the Following FormatCODE[ Minute - Hour - Day - Month - Weekday ] - CommandThe COMMAND, can be broken down in
-----displayed data-----

I understand that i have to replace the line gap by <p> or <br> when displaying it. But how to perform it. The complete content is accessed using row['content']

phparion

9:50 am on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



make sure you do not strip_tags() at the time of storing data in the database. secondly display the content before storing it with htmlspecialchar() and see if the formatting code is going with the content. Also at the time of displaying it do you have any code that strip_tags() or remove \r\n?

jatar_k

12:20 pm on Nov 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just use nl2br [php.net]

henry0

1:08 pm on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but be aware of:
using nl2br() does indeed the job
although if you provide your users or yourself with a means to keep editing the content
then you need using preg replace to get read of the original set of <br />
Why: when re-opening the previous content in textarea the "<br />" will all show up, then you edit and reload as such a new bunch of "<br />" will be created and added on the top of the previously set "<br />"

so you may use this:


/////////// remove the <br /> it could be set in a loop if needed //////////////////////

$patterns[0] = '/<br \/>/' ;

$replace[0] = ' ';

$content = preg_replace($patterns, $replace, $content);

////////// end removing <br /> ///////