Results 1 to 4 of 4

Thread: Replace <p> tags

  1. #1
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default Replace <p> tags

    Hello all,
    I am currently using tinyMCE as a WYSIWYG editor on this new site I am developing. The main problem is that the submitted code is used for layout purposes. tinyMCE uses <p> tags for new lines. I would like to replace the <p> ...</p> tags with a simple <br />. HOWEVER, If a code is submitted more than once, many <br /> tags build up.
    Here is my code so far:
    PHP Code:
        $update =str_replace("<p>"""$_POST['update']);
        
    $update =str_replace("</p>""<br />"$update); 
    Elaborate, I know. How can I prevent a <br /> tag being added if there was already one inserted from a previous time. Or maybe a way to disable <p> bindings in tinyMCE?
    TinyMCE: http://tinymce.moxiecode.com/
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    PHP Code:
    $update preg_replace("/<p>(.*?)<\/p>\n/""\n<br />$1<br />\n"$_POST['update']); 
    Something like this, or can your provide a full copy of what the input would be and what you want the conversion to be.
    Corrections to my coding/thoughts welcome.

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    fileserverdirect (10-23-2010)

  4. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    When outputting the text again, just replace <br /> with </p><p>, and add <p> before the whole string and </p> after the whole string.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Well, that actually worked pretty well. Thanks.

    Oh, and djr, you just reminded me of sharedphp! Yes sorry about not updating the post. I got a very good paying offer for a website, so sharedphp was put on a little hold. The deadline for this site is the 31'st and it's almost done, after that I'll get back to work on sharedphp, which itself is nearing completion.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

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
  •