Jump to content

Unexpected T_Var


foucquet

Recommended Posts

I am trying to bring a flickr feed into a webpage, and can't work out why this:-

 

<?php
// >>> Set up the variables needed <<<
$photos = array();
$encode_params = array();
$maximgs = 19;	 // >>> This need to be 1 less than actual req'd No. as array counts from 0 <<<
// >>> Set up the parameters for the API <<<
$api_params = array(
'api_key'	 => 'my api key',
'method'	 => 'flickr.photos.search',
'user_id'	 => 'my id',
'format'	 => 'php_serial',
);
//>>> Encode the parameters ready to make API request <<<
foreach($api_params as $k => $v){
$encode_params[] = urlencode($k) . '=' . urlencode($v);
}
var_dump($encode_params);
// >>> Construct API url and make the request <<<
$api_url = 'http://api.flickr.com/services/rest/?' . implode('&', $encode_params);
var_dump($api_url);
// >>> Retrieve images <<<
$rsp = file_get_contents($api_url);
$rsp_obj = unserialize($rsp);
echo $rsp_obj;
var-dump($rsp_obj['photos']['photo']); //>>> Line 37 <<<
?>

 

gives me "Parse error: syntax error, unexpected T_VAR in C:\wamp\www\php\flickr tests\prev3~.php on line 37".

Link to comment
https://forums.phpfreaks.com/topic/269823-unexpected-t_var/
Share on other sites

$api_params = array(
'api_key' => '1b6e67959f14d79c2c9c568b02c23f23',
'method' => 'flickr.photos.search',
'user_id' => '49466419@N05',
'format' => 'php_serial',
);

Also, there is a comma after the last element - indicating that there should be another element in the array.

Link to comment
https://forums.phpfreaks.com/topic/269823-unexpected-t_var/#findComment-1387245
Share on other sites

Commas at the ends of the array declaration are valid, oddly enough.

 

There are two places in PHP where errant commas are valid:

1) Trailing commas in array declarations:

$a = array( 1,2,3, );

 

2) Initial commas within list():

list(,$a) = explode(",", $Foo);

Link to comment
https://forums.phpfreaks.com/topic/269823-unexpected-t_var/#findComment-1387250
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.