php split alternative

hello,
how can I do the latest version of php

\
$sData = split("[\n]", $message);

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Matthew KellyCommented:
Explode is the alternative: http://php.net/manual/en/function.explode.php
0
Matthew KellyCommented:
For more information: see the Notes section of the PHP split page: http://php.net/manual/en/function.split.php

"preg_split(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to split(). If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine."

Splitting on new line characters wouldn't require regular expressions so exploded() would be faster in your case.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
The \n thing that you refer to is a newline character.  There is a context-aware built-in constant called PHP_EOL that should be used in explode() to break a file up into individual lines in an array.  The PHP_EOL character is different in different installations of PHP, and that is why you want to use the constant instead of some kind of combination of \n \r \r\n, etc.

Example in the code snippet.
$sData = explode(PHP_EOL, $message);
var_dump($message);
var_dump($sData);

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.