I have one page with textarea which content is saved into database.
The content looks like this:
before
--------------
after
Now I need to split the text into “before” and “after” – without any new line signs.
So my questions are:
On what does the EOL character depends?
a) on a platform user is running
b) on a PHP server’s platform
c) on a DB server’s platform
Is there a better cross-platform solution?
$string_exploded = explode( "\n". $delimiter. "\n", $string );
if( count($string_exploded) === 1 )
{
$string_exploded = explode( "\r\n". $delimiter. "\r\n", $string );
}
Thank you all for answers
You should be using
PHP_EOL. This will conform to the machine’s proper line ending.If you’re just pulling from the database, you should be exploding with the same character you used to join them.
Even if you’re worried about having whitespace at the end of your strings, just use
trimafterwards to be happy with yourself.