Grow your CSS skills. Land your dream job.

Last updated on:

Convert Comma Separated String into Array

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

// print_r($arr);


  1. Ariel
    Permalink to comment#

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


    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?

    • Permalink to comment#

      Lezioni, you can always use a foreach loop rather than a for loop.
      On the other had if you really want to now the lenth of an array
      use the count statement.


  4. Marco
    Permalink to comment#

    Thanks a lot! Impressive simplicity!

  5. Michael
    Permalink to comment#

    That won’t work for a lot of cases. Consider:

    Field 1, Field 1,”This is text, with a comma.”

    That string will be broken into 4 pieces when it should only be 3.

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

<div>Example code</div>

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".