SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    End paragraphs formatting

    I am using:

    $contact = ereg_replace("\n\n","<p>",$contact);

    to replace two carriage returns with a new paragraph (<p>)

    However, I need </p> to appear at the end of each paragraph. How can this be done?

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sure someone else will come up with a better solution, but I was just thinking what if you did both with one replacement? For example:
    PHP Code:
    <?php
    $contact
    =str_replace("\n\n","</p><p>",$contact);
    ?>
    str_replace is faster than ereg_replace() -- but it's up to you. The only stipulation is figuring out how to handle the initial <p>.

    Perhaps just inserting that into the $content automatically? Just an idea.
    Last edited by Aes; Jan 3, 2002 at 11:09.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not:
    PHP Code:
    $contact "<p>" str_replace("\n\n""</p><p>"$contact) . "</p>"

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh geeez. I'm dense!
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While I am sure this would be way too slow, I am feeling crafty this morning.

    BTW it might not even work.

    PHP Code:
    $contact "<p>" implode("</p><p>"explode("\n\n"$contact)) . "</p>"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    ********* Scotland Saltire's Avatar
    Join Date
    Jan 2000
    Location
    Scotland
    Posts
    660
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks folks.

    I ended up trying freddys way first and it worked. Thanks.


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
  •