【问题标题】:How can I put a PHP Variable in file_get_contents URL String?如何将 PHP 变量放入 file_get_contents URL 字符串中?
【发布时间】:2014-05-06 23:46:33
【问题描述】:

我想更改下面 URL 中的 1 并传递从网站 URL 中提取的 PHP 变量。除了在下面的 URL file_get_contents 中间有一个变量工作时遇到问题,我还有其他一切工作。

$listingstring = file_get_contents('http://example.com/1/lsitngs/');

$listingstring = file_get_contents('http://example.com/?variable/lsitngs/');

【问题讨论】:

标签: php json variables file-get-contents


【解决方案1】:

为你的字符串使用双引号,这样你就可以在其中放置一个变量并对其进行插值:

$listingstring = file_get_contents("http://example.com/$variable/lsitngs/");

你也可以使用串联:

$listingstring = file_get_contents('http://example.com/'.$variable.'/lsitngs/');

【讨论】:

  • 2 合 1 特价,奖​​金 ;-)
  • ...他们得到了多么划算!
  • 真是太好了!很好,谢谢。我选择了第二个选项。
猜你喜欢
  • 2019-08-14
  • 1970-01-01
  • 2011-12-09
  • 2014-05-30
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
相关资源
最近更新 更多