You are here: Re: strip out too many newlines « PHP « IT news, forums, messages
Re: strip out too many newlines

Posted by Al on 08/05/05 02:23

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация