How would I remove a line from the end of a string with PHP? Thanks.
+4
A:
You want to remove whitespace? Try trim(). It's close cousins ltrim and rtrim may be closer to what you want.
Kalium
2010-07-12 02:01:16
Thanks I think rtrim did it.
usertest
2010-07-12 02:18:04
A:
If you are looking to remove the last line is a string containing new line character (\n), then you'd do something like this ...
$someString = "This is a test\nAnd Another Test\nAnd another test.";
echo "SomeString BEFORE=".$someString."\n";
// find the position of the last occurrence of a \n
$firstN = strlen($someString) - strpos(strrev($someString), "\n");
// get rid of the last line
$someString = substr($someString, 0, $firstN);
echo "SomeString AFTER=".$someString;
Don Dickinson
2010-07-12 02:17:46