OK sorry about the confusing title but what I would like to do is split a bit of text like the following:
var1=hello&var2=world&foo=bar
into an array like the following
array['var1'] = hello;
array['var2'] = world;
array['foo'] = bar;
OK. There is a nice user created function in PHP to do this:
function explode_assoc($glue1, $glue2, $array)
{
$array2=explode($glue2, $array);
foreach($array2 as $val)
{
$pos=strpos($val,$glue1);
$key=substr($val,0,$pos);
$array3[$key] =substr($val,$pos+1,strlen($val));
}
return $array3;
}
But I can't seem to find one for javascript and I am very new with it so can't really change the above code into javascript.
If there is a way to do this in javascript of a way of making a custom function could you show me. Thanks very much. 🙂