Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    Textarea processing

    Hy

    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

    PHP Code:
    $tekstmanage preg_replace('/\n/',"</p>\n<p>"

    strip_tags($_POST['content']));

    $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

    PHP 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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    You might want to also look at this instead:
    http://us.php.net/nl2br

    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.

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Thanks for the link, i found quite useful comments there.


  •  

    Posting Permissions

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