Page 1 of 1

Changing a string to an array split every newline

Posted: Wed Oct 15, 2003 7:45 pm
by like_duh44
How would I go about making a string that has multiple lines into an array seperated every new line?

Code: Select all

<?php

$string = "This is my string\nAs you can tell,\nit has many new lines.\n";

$array = array();

$array = whatfunction("\n", $string);

$i = 0;
foreach ($array as $split)
{
&nbsp;&nbsp;&nbsp;echo $split[$i];
&nbsp;&nbsp;&nbsp;echo ":::::";
&nbsp;&nbsp;&nbsp;$i++;
}

//Output something like this: This is my string:::::As you can tell......

?>

Posted: Wed Oct 15, 2003 8:34 pm
by Sevengraff
explode() can be used
http://us3.php.net/explode

Posted: Thu Oct 16, 2003 4:59 am
by like_duh44
Perfect, works like a charm. Thanks mate