开发者

String concatenation in PHP

Is it possible to send some text message with an echo?

I'm looking for something like: if($xml) echo $xml+"hello world;

This is my PHP:

[...]curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com开发者_StackOverflow社区/2/upload.xml');
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

    $xml = curl_exec($curl);

    curl_close ($curl);
 if($xml) echo $xml; 
?>


Use . instead of + to concatenate in PHP.

if($xml) { echo $xml . "hello world"; }


You can use .= to append a string to a variable:

$xml .= 'Hello World';

If you just want to echo $xml followed by "Hello World", why not:

if ($xml) {
  echo $xml;
  echo 'Hello World';
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜