Jump to content

Insert Article(page1) and view article with html formatting(page2)


inquisitive

Recommended Posts

I am setting up an article database where users can enter the text of their choice via <textarea> on an add_article.php page which is processed by a separate page...and then on yet another page you can view articles...What i want to know is how to make it so that users can enter their articles minus formatting in the previous mentioned.  Pressing the enter key in the textarea box also need to be equivalent to a <br /> Then I want to echo this into the view_articles.php.

 

All I need is the processing code to enter these articles in the way I desire.

Link to comment
Share on other sites

If you want to get the text area output to have line breaks, you just use

 

<?php

$text = nl2br($_POST['your_textarea']);

?>

 

The key-stroke "Enter" doesn't actually get lost, its just that HTML can't do anything with it, as it is passed as a \n.

 

I don't really understand the rest of your post... No other formatting should be carried across in a text area... Unless you are talking about users adding their own HTML?

Link to comment
Share on other sites

I was just talking about when it is output there are appropriate paragraph breaks...links appear as they should...lists appear as unordered lists...if the list thing is too difficult that is fine...the articles just need to look good (properly formatted) and be readable.

 

Just curious what does it take to create an article submission program where you have the option to format it the way you like...kind of like emails and forums (like this one)...

Link to comment
Share on other sites

Ah, well now you'll be talking about bbcode. The nl2br() function that I mentioned previously will paragraph your text properly (or at least, as the user enters it), but other formatting tends to be a lot more complicated.

 

Creating something like this forum takes a lot of work. Why not just download an existing application - a blog would do the things that you are after, and probably be the most suitable - and use that instead?

Link to comment
Share on other sites

Should just be a case of:

 

<?php
$article = mysql_real_escape_string(stripslashes(nl2br($_POST['article'])));
?>

 

Edit:

By the way, I was just looking at php.net for mysql_real_escape_string() and I don't understand your use of it in this situation (possiblly because I can't see the rest of the code) but it seems a bit redundant here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.