0

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
12
  • What are you talking about? Commented Dec 5, 2017 at 17:58
  • Edit the PHP code in a text editor? It's not clear to me what you mean or what you're asking here. Commented Dec 5, 2017 at 17:58
  • 3
    parse_str and array_flip, and yes, arrays in general. Commented Dec 5, 2017 at 18:07
  • 2
    @userxöa You should put that comment in the question. It's completely different from what you asked, there are no PHP variables in that string. Commented Dec 5, 2017 at 18:12
  • 1
    The comment by @mario should work for you. Have you tried it? 3v4l.org/8CstD You then can iterate over $output and use the key as the var name and the value as you would. Commented Dec 5, 2017 at 18:36

2 Answers 2

1

The @mario and @chris85 solution that worked:

$string = '1064398956=NAME&1318807391=TELEPHONE';
parse_str($string, $output);
print_r(array_flip($output));
Sign up to request clarification or add additional context in comments.

Comments

0

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'

1 Comment

Multiple variables can have the same value as another.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.