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 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn