I have a Google Forms Prefilled URL
$input = "https://docs.google.com/forms/d/e/1FAIpQLSe8aZbfXa2IRRzK6hPTDKvAf_Oa8chTMrX8wkkYcuVHGs-vuA/viewform?usp=pp_url&entry.1064398956=NAME&entry.1318807391=TELEPHONE";
$pars = parse_url($input);
$values = $pars["query"];
$values = str_replace("entry.", "", $values);
$values = str_replace("usp=pp_url&", "", $values);
With this code I get values as
1064398956=NAME&1318807391=TELEPHONE
Because the numbers (entry id) are always different, I use default values (like NAME, TELEPHONE), and these would be storaged to mySQL database like this:
Id || NAME || VALUE
================================
1 || 1064398956 || 1318807391
To upload a row to that mysql database I have the query:
INSERT INTO TABLE (ID, NAME, VALUE) VALUES (1, $NAME, $VALUE)
Based on the following string, how i can find values $NAME and $VALUE?
1064398956=NAME&1318807391=TELEPHONE
The @mario and @chris85 solution that worked:
$string = '1064398956=NAME&1318807391=TELEPHONE';
parse_str($string, $output);
print_r(array_flip($output));
This code will switch the var name whit the value ($VALUE variable with 'NAME' value)
function get_var_name($vars, $var)
{
foreach ($vars as $name => $value) {
if ($value === $var) {
return $name;
}
}
return false;
}
$NAME = "VALUE";
$$NAME = get_var_name(get_defined_vars(), $NAME);
echo $VALUE; // will print 'NAME'