简体   繁体   English

解析错误:语法错误,意外T_STRING

[英]Parse error: syntax error, unexpected T_STRING in

I' making this class to catch twitter posts but I get the error : 我正在制作此类以捕获Twitter帖子,但出现错误:

Parse error: syntax error, unexpected T_STRING in /Applications/XAMPP/xamppfiles/htdocs/classTest/Twitter.php on line 29

I cant find what's wrong...any ideas? 我找不到什么问题...任何想法?

class TwitterGrub{


function twitterCapture($user = 'myUsername',$password = 'myPass') {  


           $ch = curl_init("https://twitter.com/statuses/user_timeline.xml");  
           curl_setopt($ch, CURLOPT_HEADER, 1);  
           curl_setopt($ch,CURLOPT_TIMEOUT, 30);  
           curl_setopt($ch,CURLOPT_USERPWD,$user . ":" . $password);  
           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
           $result=curl_exec ($ch);  
           $data = strstr($result, '<?');  

           $xml = new SimpleXMLElement($data);  

      return $xml;  

}  


function twitterDisplay($twitNum){
    $xml = this->twitterCapture(); 


    for($i= 0; $i<$twitNum; $i++){ 
    echo   "<div class='curvebox'>".$xml->status[$i]->text."</div>";

    }
}

}
$xml = this->twitterCapture();  

应该

$xml = $this->twitterCapture();  

The only reason I can find that you get the error you are getting is that you are not enclosing the code in php tags. 我能找到您得到的错误的唯一原因是您没有将代码包含在php标签中。 Paste the following code into codepad, and you will get a different error (I have made no other changes to your code): 将以下代码粘贴到键盘中,您将得到一个不同的错误(我对您的代码没有其他更改):

<?php
class TwitterGrub{


function twitterCapture($user = 'myUsername',$password = 'myPass') {  


           $ch = curl_init("https://twitter.com/statuses/user_timeline.xml");  
           curl_setopt($ch, CURLOPT_HEADER, 1);  
           curl_setopt($ch,CURLOPT_TIMEOUT, 30);  
           curl_setopt($ch,CURLOPT_USERPWD,$user . ":" . $password);  
           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
           $result=curl_exec ($ch);  
           $data = strstr($result, '<?');  

           $xml = new SimpleXMLElement($data);  

      return $xml;  

}  


function twitterDisplay($twitNum){
    $xml = this->twitterCapture(); 


    for($i= 0; $i<$twitNum; $i++){ 
    //echo   "<div class='curvebox'>".$xml->status[$i]->text."</div>";

    }
}

}
?>

Then make the change from this 然后从中进行更改

$xml = this->twitterCapture(); 

to

$xml = $this->twitterCapture();

and the errors will magically disappear. 错误将神奇地消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM