I need to parse data from a string the string looks like:
id|0;f|Luke;l|skywalker;email|[email protected];(etc...)
I would like to convert this to something like:
$t = array(
'id' => 0,
'f' => 'Luke',
'l' => 'Skywalker',
'email' => '[email protected]',
//....
)
Now i know I can explode then for loop then explode again but is there a shortcut to this?
Like 1 line of 1 function in PHP that will do this?
Tkx
This little snippet should take care of it in most cases:
parse_str(strtr($data, '|;', '=&'), $t);
It turns the string into something that looks like application/x-www-form-urlencoded and then parses it according to those rules.
Note that certain characters will get a different meaning such as %20 will be turned into spaces, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With