This question already has an answer here:
I have string
$string = "one
two
three
four";
Q: How to divide string by "
"
character to array as :
array ('one', 'two', 'three', 'four');
</div>
This question already has an answer here:
I have string
$string = "one
two
three
four";
Q: How to divide string by "
"
character to array as :
array ('one', 'two', 'three', 'four');
</div>
Just use the explode function and use the newline character:
$array=explode("
",$string);
print_r($array);
Having said that, different OS will use different new line breaks. Some will use
while others will use
which you might want to look into.
You can combine what you are doing with the nl2br function which covers all the options if you really want to - though I would consider it potentially overkill/complicating the issue:
$array=explode("<br>",nl2br($string,false));
print_r($array);