treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Convert Comma Separated String into Array

Last updated on:

Easy way to turn a CSV file into a parseable array.

<?php
$str="foo,bar,baz,bat";
$arr=explode(",",$str);
// print_r($arr);
?>
View Comments

Comments

  1. Ariel
    Permalink to comment#

    Is there a way to take a comma separated string like say: Tags: Something, somethingelse, thirdsomething into

    Tags:
    Something
    Somethingelse
    thirdsomething

    Perhaps by wrapping this code Tags: Something, somethingelse, thirdsomething in some kind of div? Is this possible?

  2. Gafur
    Permalink to comment#

    Thank you very much,

  3. Permalink to comment#

    Ok, but if i put the $arr in a cycle for example “for”…how can i kmow the lenght of that array?…the problem for me it’s that one…the cycle should print $arr[0],$arr[1],$arr[2],$arr[3] and then stop, how can i tell it the it has to stop on number three?

Leave a Comment

Use markdown or basic HTML and be nice.