View Full Version : Textarea processing

07-05-2007, 09:42 PM

My write to file textarea form needs a bit processing before it's saved to file. Dunno really if there is better or faster way to create this but here's the problem.

I'm processing text in textarea with simple pregreplace so that on Return (/n) it adds </p><p>

Here's the code in steps

$tekstmanage = preg_replace('/\n/',"</p>\n<p>",


$content = "<p>".$tekstmanage."</p>";

My form adds closing and starting tag wherever there is /n. But if user hits few return keys then i end up with few empty <p></p> tags.

I wanted to remove them with this code

$tekstmanage2 = preg_replace ('/</p>\n<\/p>/', '', $tekstmanage);

But i got this error

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'p' in ...\htdocs\PHP\Form_To_File\form.php on line 6

Any ideas how to remove those extra p tags? Or a better way to do the same.
Thanks in advance

07-05-2007, 10:31 PM
You might want to also look at this instead:

Changes your newlines to <br> (instead of <p></p>)

So before you save it, you use nl2br, then you could
search for multiple <br>'s .. but I don't have the code
for that.

07-06-2007, 12:59 PM
Thanks for the link, i found quite useful comments there.