Log in

View Full Version : Replace <p> tags



fileserverdirect
10-23-2010, 02:40 AM
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:


$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/

bluewalrus
10-23-2010, 04:28 AM
$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.

djr33
10-23-2010, 04:32 AM
When outputting the text again, just replace <br /> with </p><p>, and add <p> before the whole string and </p> after the whole string.

fileserverdirect
10-23-2010, 05:10 AM
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.