Displaying Formatted Content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Displaying Formatted Content

Post by kkonline »

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

Code: Select all

---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.

Code: Select all

-----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']
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

nl2br() ?

Whoa... deja-vu!
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post by kkonline »

Code: Select all

$content = nl2br($content);
               $content = str_replace("%", "", $_POST['content']);
               $content = str_replace("_", "", $content);
               $content = trim(mysql_real_escape_string($content));
It is not solving the purpose. No br tags are added to the database after doing the above processing. What could be the problem
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

re-check your code: you're overwriting the nl2br'd content from the POST array
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post by kkonline »

Kieran Huggins wrote:re-check your code: you're overwriting the nl2br'd content from the POST array
yes you are correct.

corrected code is

Code: Select all

$content = nl2br($_POST['content']);
$content = str_replace("%", "", $content);
$content = str_replace("_", "", $content);
$content = trim(mysql_real_escape_string($content));
Thanks
Post Reply