Page 1 of 1

Finding newline chars

Posted: Mon Jun 06, 2005 7:41 am
by MathewByrne
Hi,
I havn't really gotten to much into String matching and Regex but I was just wondering if there was a simple way of finding if a string has a newline character at the end of it (\n).

Posted: Mon Jun 06, 2005 8:18 am
by Chris Corbyn
Try this

Code: Select all

$string = "foo
bar
"; //Ends on newline

if (preg_match('/\n$/', $string)) {
   //End on newline
} else {
   //End some other way
}