Changing a string to an array split every newline

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Changing a string to an array split every newline

Post 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......

?>
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

explode() can be used
http://us3.php.net/explode
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Post by like_duh44 »

Perfect, works like a charm. Thanks mate
Post Reply