开发者

Parse error: syntax error, unexpected T_STRING in

I' making this class to catch twitter posts but I get the error :

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;开发者_如何学C $i++){ 
    echo   "<div class='curvebox'>".$xml->status[$i]->text."</div>";

    }
}

}


$xml = this->twitterCapture();  

should be

$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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜