Code Snippet

Home » Code Snippets » PHP » Convert Comma Separated String into Array

Convert Comma Separated String into Array

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

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

Subscribe to The Thread

  1. Ariel

    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

    Thank you very much,

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~