SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Location
    Cedarville Ohio, or Newark Delaware (summer)
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Textarea CMS programming

    I am creating a small CMS for my university newspaper. Essentially, I need to create a textarea into which the user will paste large amounts of text (the story) from Word or a text editor. It will be automatically converted into paragraphs (<p></p>).

    The part I don't know is how to convert the line breaks from the pasted text into <p> tags.

    In other words:

    This is a paragraph.
    This is a new paragraph.
    Yet another paragraph.

    changed to:

    <p>This is a paragraph.</p>
    <p>This is a new paragraph.</p>
    <p>Yet another paragraph.</p>

    Would someone help me??
    THANKS!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You'd be best advised to achieve this using PHP or some other server-side language. This is what I'd do:
    PHP Code:
    //First, put the entire input into a string:
    $str $_POST['story'];

    //Then split it into paragraphs
    $lines explode("\n"$str);

    //Add the <p> tags to each paragraph and output it
    foreach ($lines as $line) {
      echo 
    "<p>$line</p>";

    Maybe you'd need to add some code in case there are blank lines (like I have done here) which would involve checking if any of the array's elements are empty (because there would be nothing between line breaks).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •