Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15404 > unrolled thread

Syntax error help

Started bysuper70s <super70s@super70s.invalid>
First post2015-06-03 18:19 -0500
Last post2015-06-03 20:30 -0500
Articles 3 — 2 participants

Back to article view | Back to comp.lang.php


Contents

  Syntax error help super70s <super70s@super70s.invalid> - 2015-06-03 18:19 -0500
    Re: Syntax error help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-04 01:46 +0200
      Re: Syntax error help super70s <super70s@super70s.invalid> - 2015-06-03 20:30 -0500

#15404 — Syntax error help

Fromsuper70s <super70s@super70s.invalid>
Date2015-06-03 18:19 -0500
SubjectSyntax error help
Message-ID<super70s-8B1DCE.18194603062015@reader.albasani.net>
I'm getting a parse error (Parse error: syntax error, unexpected '[' in 
/home/sitename/public_html/videos/index.php on line 63) in the below 
YouTube video search script.

I believe line 63 to be...
$video = youtubeGetVideo($id)['snippet'];

This error showed up after I moved this script to a different server. I 
think it might have something to do with the new server running a 
version of PHP earlier than 5.4. Either that or there's a bracket or 
semicolon that isn't closed, however it did work OK on the other server.

If anyone has any idea what could be causing this and a fix I'd really 
appreciate it.


<?php

error_reporting(1);
include "config.php";

require_once "class.xml.php";

function prepare_and_show($left,$right){
   $file=file_get_contents("templates/main.html");
   $left=file_get_contents("templates/left.html");
   global $site_url;
   global $site_title;

   global $tag_list;
   global $adsense_id; global $cbank_id; global $showsite_url;

   if(file_exists("upgrade.php")){
      $switch=0;
      include "upgrade.php";
   }

   if(isset($sum) and md5($sum)=="4819a994e94e212e65f8d38060f9ad34"){
      $switch=1;
      include "upgrade.php";
   }
   else{
      $match=preg_split("/[,]+/", $tag_list);
      $tagshow="";
      $min=12; $max=22;
      $rand=mt_rand($min,$max); 

      $tagl_trim=str_replace(" ","+",trim($match[0])); $tagshow.="<a 
href='$site_url/tag/$tagl_trim' style='font-size: 
$rand".'px'."'>".trim($match[0])."</a> "; $rand=mt_rand($min,$max); 
$tagl_trim=str_replace(" ","+",trim($match[1])); $tagshow.="<a 
href='$site_url/tag/$tagl_trim' style='font-size: 
$rand".'px'."'>".trim($match[1])."</a> ";$rand=mt_rand($min,$max); 
$tagl_trim=str_replace(" ","+",trim($match[2])); $tagshow.="<a 
href='$site_url/tag/$tagl_trim' style='font-size: 
$rand".'px'."'>".trim($match[2])."</a> ";$rand=mt_rand($min,$max); 
$tagl_trim=str_replace(" ","+",trim($match[3])); $tagshow.="<a 
href='$site_url/tag/$tagl_trim' style='font-size: 
$rand".'px'."'>".trim($match[3])."</a> "; 
      $rand=mt_rand($min,$max); $tagl_trim=str_replace(" 
","+",trim($match[4])); $tagshow.="<a href='$site_url/tag/$tagl_trim' 
style='font-size: $rand".'px'."'>".trim($match[4])."</a> 
";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" 
","+",trim($match[5])); $tagshow.="<a href='$site_url/tag/$tagl_trim' 
style='font-size: $rand".'px'."'>".trim($match[5])."</a> 
";$rand=mt_rand($min,$max); $tagl_trim=str_replace(" 
","+",trim($match[6])); $tagshow.="<a href='$site_url/tag/$tagl_trim' 
style='font-size: $rand".'px'."'>".trim($match[6])."</a> "; 
$rand=mt_rand($min,$max); $tagl_trim=str_replace(" 
","+",trim($match[7])); $tagshow.="<a href='$site_url/tag/$tagl_trim' 
style='font-size: $rand".'px'."'>".trim($match[7])."</a> ";
   }

   $left=str_replace("{site_url}",$site_url,$left);
   $left=str_replace("{tag_list}",$tagshow,$left);

   if(isset($_GET['video']) and $_GET['video']!=""){
        $right_parse=explode("<!-- return title -->",$right);
        $right=$right_parse[0];
        $sec_parse=explode("<!-- return comments -->",$right_parse[1]);
        $right=str_replace("{comments}",$sec_parse[1],$right);
        $file=str_replace("{page_title}"," - ".$sec_parse[0],$file);
   }else{
      $file=str_replace("{page_title}","",$file);
   }

   $file=str_replace("{site_url}",$site_url,$file);
   $file=str_replace("{showsite_url}",$showsite_url,$file);
   $file=str_replace("{site_title}",$site_title,$file);
   $file=str_replace("{left}",$left,$file);
   $file=str_replace("{right}",$right,$file);
   $file=str_replace("{adsense_id}",$adsense_id,$file);
   $file=str_replace("{cbank_id}",$cbank_id,$file);
   return $file;
}

function get_video($id){
    include_once "youtube.php";
    global $site_url;

    $video = youtubeGetVideo($id)['snippet'];
    $title = $video['title'];
    $description = $video['description'];
    $description = htmlentities(substr($description, 0, 1000));
    $channel = $video['channelTitle'];

(etc., etc.)

[toc] | [next] | [standalone]


#15405

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-06-04 01:46 +0200
Message-ID<mko3kl$1sr$1@solani.org>
In reply to#15404
super70s wrote:

> I'm getting a parse error (Parse error: syntax error, unexpected '[' in 
> /home/sitename/public_html/videos/index.php on line 63) in the below 
> YouTube video search script.
> 
> I believe line 63 to be...
> $video = youtubeGetVideo($id)['snippet'];
> 
> This error showed up after I moved this script to a different server. I 
> think it might have something to do with the new server running a 
> version of PHP earlier than 5.4. Either that or there's a bracket or 
> semicolon that isn't closed, however it did work OK on the other server.
> 
> If anyone has any idea what could be causing this and a fix I'd really 
> appreciate it.

Indeed, this syntax is available only as of PHP 5.4.0: "Function array
dereferencing has been added, e.g. foo()[0]."[1]  For older versions
(which might better be avoided, because they are no longer supported),
you can get around the issue by assigning the function return value to
an auxiliary variable, and to access the desired element on that:

  $aux = youtubeGetVideo($id);
  $video = $aux['snippet'];

[1] <http://php.net/manual/en/migration54.new-features.php>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#15406

Fromsuper70s <super70s@super70s.invalid>
Date2015-06-03 20:30 -0500
Message-ID<super70s-781AAC.20305303062015@reader.albasani.net>
In reply to#15405
In article <mko3kl$1sr$1@solani.org>,
 "Christoph M. Becker" <cmbecker69@arcor.de> wrote:

> super70s wrote:
> 
> > I'm getting a parse error (Parse error: syntax error, unexpected '[' in 
> > /home/sitename/public_html/videos/index.php on line 63) in the below 
> > YouTube video search script.
> > 
> > I believe line 63 to be...
> > $video = youtubeGetVideo($id)['snippet'];
> > 
> > This error showed up after I moved this script to a different server. I 
> > think it might have something to do with the new server running a 
> > version of PHP earlier than 5.4. Either that or there's a bracket or 
> > semicolon that isn't closed, however it did work OK on the other server.
> > 
> > If anyone has any idea what could be causing this and a fix I'd really 
> > appreciate it.
> 
> Indeed, this syntax is available only as of PHP 5.4.0: "Function array
> dereferencing has been added, e.g. foo()[0]."[1]  For older versions
> (which might better be avoided, because they are no longer supported),
> you can get around the issue by assigning the function return value to
> an auxiliary variable, and to access the desired element on that:
> 
>   $aux = youtubeGetVideo($id);
>   $video = $aux['snippet'];
> 
> [1] <http://php.net/manual/en/migration54.new-features.php>

That did it! Thank you very much Chris.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web