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
Don't know much about the app you're writing, but does this do the trick for
you?
echo preg_replace ('!
(
\[quote
(?:=[^\]]*)?
\]
)# Capture the [quote=xxx] part
thanx for the reply, but 1 problem. there is not only \n there are \r in
the POST too (carriage returns) so a string can look like this:
$string = '[quote=xx]\r\nfoo\r\n[/quote]\r\nmore text\r\n\r\n\r\n\r\n';
and your regexp will only catch if there is just \n
any solution for \r\n in
Try changing the
\n*
patterns to
(?:\r?\n)*
Cheers,
Marco
--
BeebleX - The PHP Search Engine
http://beeblex.com
On 8/4/05 10:39 AM, Sebastian [EMAIL PROTECTED] wrote:
[quote=user]
foo
[/quote]
bunch of extra lines
more text...
--
PHP General Mailing List (http://www.php.net/)
that works for my orginal request, but i found something else:
$string = '[quote=xx]foo[/quote]\nmore text\r\n\r\n\r\n\r\nmore text';
now if they enter more carriage returns i get the results from above.
its no big deal, but you always have someone trying to 'break' the system.
thanks, i
On 8/4/05 10:56 AM, Sebastian [EMAIL PROTECTED] wrote:
that works for my orginal request, but i found something else:
$string = '[quote=xx]foo[/quote]\nmore text\r\n\r\n\r\n\r\nmore text';
Try removing double-instances of \r\n (or \n) before running the regex.
Marco
now if they enter
6 matches
Mail list logo