I’ve got this text
“?foo=bar&foobar=barfoo”
what is the best way to convert this text to variables? Like this:
<?php
echo $q['foo']; //bar
echo $q['foobar']; //barfoo
?>
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
see http://docs.php.net/parse_str and http://docs.php.net/parse_url
prints
edit: If you know the string always has the form ?x=y… you might want to skip parse_url() and use substr() instead.
edit2: Keep in mind that the behavior of parse_str() depends on the value of arg_separator.input. Should you set it (for whatever reason) to something like ‘!’ parse_string() will return NULL for your input string.
e.g.
prints
NULL. But …that would be a rather odd setting.