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".

Edited by foucquet
Link to comment
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.

Edited by Psycho
Link to comment
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);

Edited by ManiacDan
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.