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).
Finding newline chars
Moderator: General Moderators
- MathewByrne
- Forum Commoner
- Posts: 38
- Joined: Sat Mar 27, 2004 9:49 pm
- Location: Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Try this
Code: Select all
$string = "foo
bar
"; //Ends on newline
if (preg_match('/\n$/', $string)) {
//End on newline
} else {
//End some other way
}