Jump to content

Turning a comma seperated list into an array


writer

Recommended Posts

I'd like to create a simple input form (field + submit button) that takes a comma separated list of locations (Paris, Hungary, Prague, etc.), strips the comma and turns the answers into an array ( $ar_locations = (1->Paris, 2->Hungary... etc.) ).

 

Any idea of some resources with which I can do this?

That syntax is incorrect. Do this instead:

<?php
$str = 'This,is,a,comma,separated,list,of,values';
$ary = explode(',',$str);
echo '<pre>' . print_r($ary,true) . '</pre>'; // show the new array
?>

 

Ken

 

Ahahaha, I thought he said semicolon.  I need to read more careful.  Thanks.

$expld_array = explode(';' $string_w_semicolon);

 

Fill it in with the right string, lol.

This is correct.

$csv = "Comma,separated,thing,";

$expld_array = explode(',' $csv);

 

Fill it in with the right string.

Thanks, to the dude who corrected me.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.