php - Explode on new line works with "\n" but not with PHP_EOL. Why? -
i have string
as can see, contains new line. want split message array of 2 messages , figured i'd utilize explode()
in combination php_eol
, multi-os functionality, left surprised did not work.
explode(php_eol, $str); // array( [0] => "divakat has attacked gergana, dealing 591 physical damage. ( 2 absorbed ) // gergana has died." ) explode("\n", $str); // array( [0] => ""divakat has attacked gergana, dealing 591 physical damage. ( 2 absorbed )", [1] => "gergana has died." )
i ask, why first illustration not working expect to, , there way can create work, because not have hardcode new line character in there. give thanks you.
edit:i forgot mention, message has been created on same machine code beingness tested. there no os changes.
php_eol
represents end-of-line sequence platform on. not magically create end-of-line sequence used within string same of platform.
for example, string \n
(the unix eol hardcoded):
$str = "hello\nworld";
if run on unix system, print 2:
echo count(explode(php_eol, $str));
but on platform print 1 because $str
contains neither windows nor mac eol sequence.
update: doesn't create difference where input created; how created. can create string unix eols on windows scheme including hardcoded \n
s in it.
php
No comments:
Post a Comment