【问题标题】:Why is the variable's value not substituted in the string?为什么变量的值没有在字符串中替换?
【发布时间】:2010-09-20 07:17:45
【问题描述】:

嘿,谁能帮帮我... 当我这样写时:

$file=file_get_contents('https://graph.facebook.com/me?access_token=1932993|twetrg|vsfgsewr');

代码也得到了很好的响应。

但是当我这样写时:

1. $tk='';
2. $tk='1932993|twetrg|vsfgsewr';//intialize the token value to variable
3. $file=file_get_contents('https://graph.facebook.com/me?access_token=$tk');

然后第 3 行显示警告为“未能打开流:HTTP 请求失败!”

请帮帮我

【问题讨论】:

    标签: php variables string-substitution


    【解决方案1】:

    变量插值不会发生在单引号中。

    所以使用双引号作为:

    $file=file_get_contents("https://graph.facebook.com/me?access_token=$tk");
    

    或者你可以这样做:

    $file=file_get_contents('https://graph.facebook.com/me?access_token='.$tk);
    

    【讨论】:

    • 附带说明,OP 中的第 1 行不是必需的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2020-08-14
    • 2020-02-04
    相关资源
    最近更新 更多