This question already has an answer here:
I have a string like this:
$values = "[121],[622],[872]";
I would like to convert this into an array, I would like each number in the square brackets to be an array item.
any suggestions how I can do this?
</div>
Seriously? Use explode()
$values = "[121],[622],[872]";
$values = str_replace(array("[", "]"), "", $values);
$values = explode(",", $values);
Or in a simpler way:
$array = explode("," ,str_replace(array("[", "]"), "", $values));
This gives values as:
Array
121
622
872
$array = explode(',',str_replace(array('[',']'),array('',''),$values));
See This
$values = "[121],[622],[872]";
$values = substr($values,1);
$values = substr($values,0,-1);
$arr = explode("],[",$values);
Hope this helps