Split string to array

php Add comments

If you want to use split to check on line feeds (\n), the following won’t work:

$line = split("\n", $input_several_lines_long);

You really have to do this instead, notice the second slash:

$line = split("\\n", $input_several_lines_long);

Be advised:

$arr = split("x", "x" );
print_r($arr);

will output:

Array
(
[0] =>
[1] =>
)

That is it will catch 2 empty strings on each side of the delimiter.

Leave a Reply

You must be logged in to post a comment.

WebSite Powered by webHauser
Entries RSS Comments RSS Login