How to separate word in php ?
Example i have one variable str = “a1,c1,d1;a2,c2,d2;a3,c3,d3”;
I want to separate str in to the following formats:
tt1=a1,c1,d1, tt2=a2,c2,d2, tt3=a3,c3,d3
How to do like this in php?
it try this but not correct:
$str = "a1,c1,d1;a2,c2,d2;a3,c3,d3";
$strSplit = explode(';', $str);
$final = array();
for($i=0, $j=0; $i<count($strSplit); $i++, $j++)
{
$final[$j] = $strSplit[$i] . ' ' . $strSplit[$i+1];
}
Does simply
…not give you what you want??
Or do you want the parts as variables in the their own right, starting with ‘tt’?
Or possibly as an array of arrays?
Or do you want to replace the semi-colon (
;) characters with spaces?