note 98391 added to function.nl2br

From: Date: Sat, 12 Jun 2010 04:40:35 +0000
Subject: note 98391 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-170079@lists.php.net to get a copy of this message
This function will change new lines (line breaks) to <br/> and it allows you to limit the amount of brs allowed at any point in time. This function was made to avoid people spaming a textarea with hundreds of line breaks or empty lines. <?php function nl2br_limit($string, $num){ $dirty = preg_replace('/\r/', '', $string); $clean = preg_replace('/\n{4,}/', str_repeat('<br/>', $num), preg_replace('/\r/', '', $dirty)); return nl2br($clean); } echo nl2br_limit($string,'4'); ?> // Heres how it works // nl2br_limit($string, $num) // $string is the entered text you want to strip lines out of, it could be ($_POST['myinput']) // $num is the amount of consecutive <br/>'s that are allowed any at a time. The user is allowed to enter as many line breaks as $num allows ---- Server IP: 69.147.83.197 Probable Submitter: 74.136.34.112 ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- https://master.php.net/note/edit/98391 Del: integrated -- https://master.php.net/note/delete/98391/integrated Del: useless -- https://master.php.net/note/delete/98391/useless Del: bad code -- https://master.php.net/note/delete/98391/bad+code Del: spam -- https://master.php.net/note/delete/98391/spam Del: non-english -- https://master.php.net/note/delete/98391/non-english Del: in docs -- https://master.php.net/note/delete/98391/in+docs Del: other reasons-- https://master.php.net/note/delete/98391 Reject -- https://master.php.net/note/reject/98391 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170079) next »