Michael
Michael

Reputation: 327

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/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; 
?>

Upvotes: 4

Views: 776

Answers (2)

starsinmypockets
starsinmypockets

Reputation: 2294

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';
}

Upvotes: 2

ceejayoz
ceejayoz

Reputation: 180024

Use . instead of + to concatenate in PHP.

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

Upvotes: 3

Related Questions