开发者

Using PHP, can I put variables inside of variables?

For example, take this code:

$ch = curl_init($resultSet['url']."?get0=get0&get1=".$get1."&get2=".开发者_如何学JAVA$get2."&get3=".$get3);

This of course, looks very ugly, and kind of a pain in the ass to read. So my question is, would I be able to use something like this:

$allgets ="?act=phptools&host=".$host."&time=".$duration."&port=".$port;
$ch = curl_init($resultSet['url'] . $allgets);

Very simple question I suppose, but my server is undergoing maintenance, so I can't upload it and test it myself. I suppose a yes or no answer will suffice, but if you have a more efficient way of doing this, that would be even better. :)


Definitely, it's just string concatenation.

You could also take a look at string variable parsing if you want it to be "less messy".


Your example might not work depending on the value of the variables because you didn't use URL-encoding.

A better way is something like this,

$fields = array (
   'host' => $host,
   'port' => $port
);

$ch = curl_init($resultSet['url'] . '?' . http_build_query($fields));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜