doubaoxue5788 2013-04-23 16:12
浏览 60

在URL末尾添加变量 - PHP

I want to append the variable $name to the URL http://google.com/script.php so that I can call the variable in another script.

How do I modify the following code without having those syntax errors?

Thanks.

Codes:

$name = $_GET['smsname'];
$call = $client->account->calls->create('+103632', $number,                                             
        'http://google.com/script.php'
    );
  • 写回答

2条回答 默认 最新

  • doumianfeng6979 2013-04-23 16:14
    关注

    Just concatenate it using .

    $var1 = 'text'; $var2 = 'text2';

    Concatenation = $var1.$var2;

    In your case.

    $name = $_GET['smsname'];
    $call = $client->account->calls->create('+103632', $number,                                             
            'http://google.com/script.php?name='.$name;
        );
    

    But, you should validate $name for values, as in if it is empty or not. Because, that code of yours will only works if if script.php?name= has a value, but if it is not, then you should be prepared to do something instead. like this:

    ex: $name = isset($_GET['smsname']) ? $_GET['smsname'] : 0;

    The above code pretty much says, if script.php?name= is set to some value, then assign it to $name else $name should be 0

    The : 0; part, is there to set a value of 0 IF nothing is set or if $_GET['smsname'] is empty. You can add anything you like there

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题