PHP Code Snippet - Check for new line characters

PHP Code Snippet - Check for new line characters

PHP Code Snippet - Check for new line characters

PHP code snippet to check new lines in a string. NoNewLines function checks given string. Function return TRUE if there are no new line characters in given string, if not function will return FALSE.

Bookmark:

PHP Code Snippet - Check for new line characters

This PHP code snippet makes sure there are no new line characters in given string. This function uses regular expression to match string pattern to check for new line characters. These code snippets useful to block spammers/hackers attempt to pass malicious data to PHP scripts.

function NoNewLines($text)
{
   return preg_match("/(%0A|%0D|\\n+|\\r+)/i", $text) == 0;
}


PHP Keywords Used:

  • preg_match

Code Snippet Information:

  • Applies To: PHP, Spammers/Hackers Blocking, Regular Expression
  • Programming Language : PHP

External Resources:

Administrator :: August 12-2009 :: 06:12 PM

Try this - [\\r\\n|\\r]+

Himanshu Porwal :: August 12-2009 :: 11:16 AM

Hello,
Can you suggest me a reular expression so that i can check for new lines in any text.
i want to check for both \r\n and \n if any of the above two occurs then replace it with


reply me ASAP
Thanks

Leave a comment