Jump to content
MakeWebGames

Forum Error


Chuckster

Recommended Posts

a small example to get you to the right direction

This function will change new lines (line breaks) to

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.

 

function nl2br_limit($string, $num){

$dirty = preg_replace('/\r/', '', $string);
$clean = preg_replace('/\n{4,}/', str_repeat('
', $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

's that are allowed any at a time.

The user is allowed to enter as many line breaks as $num allows

 

php.net

or you can use -->> stripslashes($_REQUEST['post']) if im not mistaken

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...