开发者

Including a function inside single quotes

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=$c开发者_开发技巧lient&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.


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 function

Have 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:

$request = 'http://test.com/next.xml?file=' . $client . '&test=' . urlencode($pro);

Use whitespaces between dots and strings - just make a rule for this. And you will see all you typos!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜