Forum Moderators: coopster
Okay, this is probably really simple, and there are probably tutorials out there for it... but..
I'm creating my first (1st) dynamic website, and one of the elements I'm including is news articles. Now, I can get the query join I need for topics, authors, and everything. Now, I just need to be able to enter and then display the content of the article.
right now, entering the article dosen't retain page breaks. i.e. I lose my paragraphs. Can anyone point me to a resource that'll teach me how to retain page breaks from the entry form, and how to format them when retrieved for display? Thanks for your help!
Oni
// Grab the submitted form data
$data = $_POST['content'];
// Convert the carriage return (new line) to breaks using nl2br()
$data = nl2br($data);
Now the data is formatted. However, if you want valid <p> tags for new lines, do something like this:
$data = trim($data);
$data = "<p>".$data."</p>";
$data = str_replace("\n\n",'</p><p>',$data)
// Note the reversed order of the P tags. This closes and reopens the next paragraph.
Now you have <p> tags instead. Just remember to hit return twice to get the paragraph :) You can also call nl2br after that.. If ya want. I prefer the <p> method without the nl2br so that I can format the source.
Now, to display the code for editting in a text box you need to convert the brackets, etc into special char codes so it will display right. YOu can read a bit about that and the reverse effect here:
[us3.php.net...]