Re: Regex Form Filter Help

From: Date: Thu, 28 Mar 2002 09:51:56 +0000
Subject: Re: Regex Form Filter Help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-90496@lists.php.net to get a copy of this message
Hello James, "James Taylor" <jtx@nestllc.com> wrote in message news:20020327203939.B04F120D07F@shell.hatesville.com... > I have a site where users can type whatever they want in and it posts it to a > database. I'm trying to eliminate whatever types of abuse I can think of, > and, since I'm using nl2br on the posts, I'm afraid a user might just hold > down enter for a couple of seconds and scroll everything off the page. I'm > trying to figure out a regex pattern that searches for say, more than 5 <br > /> strings in a row, and anything after 5 gets stripped out. Any ideas on > how to possibly do this? First of all, store all of your information in your database as it's entered, and perform the regex and other string manipulation on the code when you bring it out of the database. That way, if you decide you could do something better than you're currently doing later on, you have the "raw data to deal with." Anyway, now to your problem: <? $string = "lots of new lines grrrrrrrrrrrrrr!"; // Change the 2 to whatever you want: if you want // to limit to three new lines, change to 3 and add another // \n (new line) $string = preg_replace("/(\r?\n){2,}/", "\n\n", $string); echo nl2br($string); ?> Hope it helps. James

« previous php.general (#90496) next »