在单引号内包含函数
我试图弄清楚为什么我不能在其中包含函数。我正在尝试将其添加到请求字符串中。 http://test.com/next.xml?file=$client&test=againtest
$client
被定义为我数据库中的文本。
function update($pro){
$request = 'http://test.com/next.xml?file='.$client'&'.'test='.urlencode($pro);;
$postargs = 'status='.urlencode($pro);
return $this->process($request,$postargs);
}
有某种方法可以做到这一点吗?这不会给我任何 PHP 错误,但它无法正常工作。如果我删除 '.$client.'
并将其替换为纯文本,例如 text
它可以工作,但是当我将其作为函数包含时,它将无法工作。
I am trying to figure out why I can't include a function into this. I am trying to make it so $client
will make it's way into the request string. http://test.com/next.xml?file=$client&test=againtest
$client
IS DEFINED as text from my database.
function update($pro){
$request = 'http://test.com/next.xml?file='.$client'&'.'test='.urlencode($pro);;
$postargs = 'status='.urlencode($pro);
return $this->process($request,$postargs);
}
Is there a certain way to do this? This doesn't give me any PHP errors, but it's not working right. If I remove '.$client.'
and replace it with just plain text such as text
it works, but when I include it as a function, it won't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来
$client
未定义。它将不可用。
如果该变量定义在函数的范围之外,则除非将其定义为全局变量
global $client
,否则不过,这是不鼓励的,更好的方法是传递
$client
作为函数的参数查看这里有关变量范围的更多信息 http://php.net/manual/en/language.variables.scope.php
It looks like
$client
isn't defined.If that variable is defined out of the function's scope, it will not be available unless you define it as a global variable
global $client
This is discouraged though, a better way of doing this is to pass
$client
as a parameter to the functionHave a look here for more on variable scopes http://php.net/manual/en/language.variables.scope.php
您应该像这样更改代码,忘记字符串连接:
在点和字符串之间使用空格 - 只需为此制定规则即可。你会看到所有的错别字!
You should change your code like this, you forget about string concatenation:
Use whitespaces between dots and strings - just make a rule for this. And you will see all you typos!