dongxi7704 2017-12-05 17:57
浏览 146
已采纳

如何从字符串中替换变量名和变量值?

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
  • 写回答

2条回答 默认 最新

  • dra8603 2017-12-05 18:44
    关注

    The @mario and @chris85 solution that worked:

    $string = '1064398956=NAME&1318807391=TELEPHONE';
    parse_str($string, $output);
    print_r(array_flip($output));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?