i have a text result from database like this:
var1=value1&var2=value2&var3=value3
How to convert into a variable and get the value?
答案 0 :(得分:4)
$str = "var1=value1&var2=value2&var3=value3";
parse_str($str, $output);
print_r($output);
Array
(
[var1] => value1
[var2] => value2
[var3] => value3
)
manual page:http://php.net/manual/en/function.parse-str.php
答案 1 :(得分:1)
This works too:
<?php
$string = "var1=value1&var2=value2&var3=value3";
$string = explode("&", $string);
foreach($string as $key) {
$result = strrchr($key,"=");
$result = trim($result, "=");
echo $result . "<br>";
}
?>