【发布时间】:2016-01-14 18:18:39
【问题描述】:
我不明白为什么这个变量在这个类中不起作用,出现以下错误:
Parse error: syntax error, unexpected '$_SERVER' (T_VARIABLE)
我读到它应该按以下方式使用:$this->url() 但似乎 PHP 不允许在类中使用变量或超全局变量,有没有办法解决这个问题?
class socialCounter
{
public $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
public function getPlus()
{
$html = file_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode($this->url());
libxml_use_internal_errors(true);
$doc = new DOMDocument(); $doc->loadHTML($html);
$counter=$doc->getElementById('aggregateCount');
return $counter->nodeValue;
}
public function getTweets(){
$json = file_get_contents( "http://urls.api.twitter.com/1/urls/count.json?url=".$this->url() );
$ajsn = json_decode($json, true);
$cont = $ajsn['count'];
return $cont;
}
}
【问题讨论】:
标签: php