解析错误:语法错误,带有来自sharrre.php的脚本的意外T_OBJECT_OPERATOR

时间:2012-05-30 20:18:08

标签: php

我需要在我的网站上运行此脚本,而我根本没有使用PHP的经验

当我调用以下脚本时

<?php
  //Sharrre by Julien Hany
  $json = array('url'=>'','count'=>0);
  $json['url'] = $_GET['url'];
  $url = urlencode($_GET['url']);
  $type = urlencode($_GET['type']);

  if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){
    if($type == 'googlePlus'){  //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
      $content = parse("https://plusone.google.com/u/0/_/+1/fastbutton?url=".$url."&count=true");

      $dom = new DOMDocument;
      $dom->preserveWhiteSpace = false;
      @$dom->loadHTML($content);
      $domxpath = new DOMXPath($dom);
      $newDom = new DOMDocument;
      $newDom->formatOutput = true;

      $filtered = $domxpath->query("//div[@id='aggregateCount']");
      $json['count'] = str_replace('>', '', $filtered->item(0)->nodeValue);
    }
    else if($type == 'stumbleupon'){
      $content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url");

      $result = json_decode($content);
      $json['count'] = $result->result->views;
      if( !isset($json['count']) ) $json['count'] = 0;
    }
    else if($type == 'pinterest'){
      $content = parse("http://api.pinterest.com/v1/urls/count.json?callback=&url=$url");

      $result = json_decode(str_replace(array('(', ')'), array('', ''), $content));
      $json['count'] = $result->count;
      if( !isset($json['count']) ) $json['count'] = 0;
    }
  }
  echo str_replace('\\/','/',json_encode($json));

  function parse($encUrl){
    $options = array(
      CURLOPT_RETURNTRANSFER => true, // return web page
      CURLOPT_HEADER => false, // don't return headers
      CURLOPT_FOLLOWLOCATION => true, // follow redirects
      CURLOPT_ENCODING => "", // handle all encodings
      CURLOPT_USERAGENT => 'sharrre', // who am i
      CURLOPT_AUTOREFERER => true, // set referer on redirect
      CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
      CURLOPT_TIMEOUT => 10, // timeout on response
      CURLOPT_MAXREDIRS => 3, // stop after 10 redirects
      CURLOPT_SSL_VERIFYHOST => 0,
      CURLOPT_SSL_VERIFYPEER => false,
    );
    $ch = curl_init();

    $options[CURLOPT_URL] = $encUrl;  
    curl_setopt_array($ch, $options);

    $content = curl_exec($ch);
    $err = curl_errno($ch);
    $errmsg = curl_error($ch);

    curl_close($ch);

    if ($errmsg != '' || $err != '') {
      /*print_r($errmsg);
      print_r($errmsg);*/
    }
    return $content;
  }
?>

我收到以下错误:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 20

第20行

$json['count'] = str_replace('>', '', $filtered->item(0)->nodeValue);

有任何建议可以帮我解决这个问题。

谢谢。

这是该文件的链接 https://bizonbytes.com/miscellaneous/sharrre.php?url=https%3A%2F%2Fbizonbytes.com%2F&type=googlePlus

我还有一个测试文件,以确保PHP正常工作 https://bizonbytes.com/miscellaneous/test.php

我将php版本更新为5,现在运行时它可以运行 http://bizonbytes.com/miscellaneous/sharrre.php

但如果我尝试以下内容 https://bizonbytes.com/miscellaneous/sharrre.php?url=https%3A%2F%2Fbizonbytes.com%2F&type=googlePlus

我收到以下错误:

Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in C:\Inetpub\vhosts\bizonbytes.com\httpdocs\miscellaneous\sharrre.php on line 56
{"url":"https://bizonbytes.com/","count":""}

我查看了ini文件,其标记为safe_mode = off,我不确定要为open_basedir添加什么

1 个答案:

答案 0 :(得分:1)

此处使用的方法链接功能直到第5版才会引入:

$filtered->item(0)->nodeValue

您需要一个更现代的版本才能运行此代码。或者,您可以手动将调用卸载到临时变量中:

$temp = $filtered->item(0);
$json['count'] = str_replace('>', '', $temp->nodeValue);

(敲出以前的错误答案:)

  

这是你的错误:

$filtered->item(0)->nodeValue
     

我猜它应该是:

$filtered->item[0]->nodeValue
     

即,引用数组的第一个元素,而不是调用a   对象的方法。