curly_brackets
curly_brackets

Reputation: 5598

PHP variable with minus in

I'm modifying a script where I want to get some server stats, where I've put my server key as one of the variables. I fear that the variable can't have minus within them. Is that true?

See line 3.

// Convert lists to JSON
$postdata=array();
$postdata['id']="534f7035-cef8-48aa-b233-8d44a0956e68";

// Run POST Request via CURL
$c2=curl_init('http://api.bf3stats.com/'.$platform.'/server/');
curl_setopt($c2,CURLOPT_HEADER,false);
curl_setopt($c2,CURLOPT_POST,true);
curl_setopt($c2,CURLOPT_USERAGENT,'BF3StatsAPI/0.1');
curl_setopt($c2,CURLOPT_HTTPHEADER,array('Expect:'));
curl_setopt($c2,CURLOPT_RETURNTRANSFER,true);
curl_setopt($c2,CURLOPT_POSTFIELDS,$postdata);
$id=curl_exec($c2);
$statuscode=curl_getinfo($c2,CURLINFO_HTTP_CODE);
curl_close($c2);

if($statuscode==200) {
    // Decode JSON Data
    $id=json_decode($id,true);
} else {
    echo "BF3 Stats API error status: ".$statuscode;

}

Upvotes: 0

Views: 198

Answers (3)

Lusitanian
Lusitanian

Reputation: 11132

Your code will work fine, however; since you're not parsing any variables in the string, you might as well use single quotes (') instead of double quotes ("). The micro-optimization factor of it makes virtually no difference, but it'll ensure you never have any accidental results after modifying the string.

Upvotes: 2

KPath001
KPath001

Reputation: 870

No, Your code is perfectly fine the way it is because of the quotations and because the variable doesn't start with it

Upvotes: 3

Sibin Grasic
Sibin Grasic

Reputation: 714

Since the variable you have defined is around quotation marks, PHP will treat it as a string. So it can have any character.

Upvotes: 2

Related Questions