[英]How do i echo php for json string?
i need to echo $account into $url so that the url/path is whatever i get from $account plus the extension json. 我需要在$ url中回显$ account,以便url / path是我从$ account加上扩展名json得到的。 I can't figure it out with the quotes.
我无法用引号弄清楚。 i tried single and double quotes but no luck.
我尝试单引号和双引号,但没有运气。 any ideas?
有任何想法吗?
<?php
$account = $_POST['account'];
$url = 'echo $account.json'; //
$content = file_get_contents($url);
$json = json_decode($content, true);
?>
Like this? 像这样?
<?php
$account = $_POST['account'];
$url = $account. '.json'; //
$content = file_get_contents($url);
$json = json_decode($content, true);
?>
the .
的
.
operator is used for string concatenation in php. 运算符用于php中的字符串连接。 This means take the value of
$account
and append the string .json
to the end, and store that in the variable $url
. 这意味着将
$account
的值附加到字符串.json
的末尾,并将其存储在变量$url
。 The rest of the code looks all right from there. 其余的代码从那里看起来还不错。 There are a few other ways to do this as well with strings in php, but I find this one simplest.
还有一些其他方法也可以用php中的字符串来做到这一点,但是我发现这是最简单的。
You can do this as this 你可以这样
$account = $_POST['account'];
$content = file_get_contents($account.'.json');
$json = json_decode($content, true);
Need I remind you how, vulnerable your codes are to injection? 我需要提醒您,代码容易受到攻击吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.