Re: strip out too many newlines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sebastian wrote:
im working on a comment/forum app and when a user enters too many carriage returns i want to remove them before insert to db.

example, user input:

-----snip-----
[quote=user]
foo
[/quote]

<bunch of extra lines>

more text...
-----snip-----


I to change to:

[quote=user]foo[/quote]

more text...

i try this regexp:

$message = preg_replace('#(\[quote(=(&quot;|"|\'|)([^\]]*)\\3)?\])\s+#i', "\\1\n", $_POST['message']);

doesn't remove / replace anything.
I need for it to work when they use [quote=xx] or [quote] and ends with [/quote]
any help?



$str= preg_replace("%(\r\n|\r|\n)%", "\n", $str);

$str= preg_replace("%\n\n+%", "\n\n", $str);			//max 2 \n

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux