Question

I am sort of new using PHP arrays. Now I got a little problem. I create a PHP file that will get some hits out of the JSON from YouTube. Now when I run my application on my localhost it runs just fine, but when I'm trying to run it on my school's host, I get an error.

This is my code:

<?php
//de database toeschrijven. ($.ajax in main.js!!!!) !!
if(isset($_POST['zoekTerm'])){
$zoekterm = $_POST['zoekTerm'];

//Query uitvoeren!!!
$add = mysqli_query ($conn,"/*My SQL Query*/");





//JSON lijst inladen en als query de variabel $zoekterm gebruiken.
$tubeApiUrl = file_get_contents('http://gdata.youtube.com/feeds/api/videos?alt=json&q='.$zoekterm.'&orderby=published&max-results=3&v=2');
$tube_json = json_decode($tubeApiUrl, true);

 $flickrApiUrl = file_get_contents('http://api.flickr.com/services/feeds/photos_public.gne?tags='.$zoekterm.'&format=json&nojsoncallback=1');
 $flickr_json = json_decode($flickrApiUrl, true);

//Compleet overzicht YOUTUBE-JSON, uncommented laten indien niet nodig. Is handig om de JSON tree te volgen.
//echo "<pre>";
//print_r ($tube_json);
//echo "</pre>";


//Per JSON entry een video uitladen en aan een variabel linken!
$hit1 = $tube_json['feed']['entry'][0]['media$group']['yt$videoid']['$t'];
$hit2 = $tube_json['feed']['entry'][1]['media$group']['yt$videoid']['$t'];
$hit3 = $tube_json['feed']['entry'][2]['media$group']['yt$videoid']['$t'];


$hit4 = $flickr_json['items'][0]['link'];
$hit5 = $flickr_json['items'][1]['link'];
$hit6 = $flickr_json['items'][2]['link'];




//Video's die uit JSON zijn gehaald in een Array stoppen.
$array = [$hit1, $hit2, $hit3, $hit4, $hit5, $hit6];
$tube_json_encode = json_encode($array);


//De terug gecodeerde JSON printen naar Google Chrome Console (Network)!!!
print_r ($tube_json_encode);

And then the error:

Parse error: syntax error, unexpected '[' in /home/stud/0861108/public.www/herkansing_imp3/back-end/add_tag.php on line 44

Was it helpful?

Solution

I wonder what version of php you are using, use square brackets [] for array is only supported in php 5.4

$array = [$hit1, $hit2, $hit3, $hit4, $hit5, $hit6];

Use normal way if you are under that version

$array = array($hit1, $hit2, $hit3, $hit4, $hit5, $hit6);

OTHER TIPS

$array = [$hit1, $hit2, $hit3, $hit4, $hit5, $hit6];

This syntax only works in PHP 5.4. If you are using an older version, it will fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top