Ошибка разбора: синтаксическая ошибка, неожиданный T_STRING в - PullRequest
0 голосов
/ 26 мая 2010

Я делаю этот класс, чтобы ловить посты в твиттере, но Я получаю ошибку:

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

Не могу найти, что не так ... есть идеи?

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>";

    }
}

}

Ответы [ 2 ]

4 голосов
/ 26 мая 2010
$xml = this->twitterCapture();  

должно быть

$xml = $this->twitterCapture();  
0 голосов
/ 26 мая 2010

Единственная причина, по которой я могу обнаружить, что вы получаете сообщение об ошибке, заключается в том, что вы не заключаете код в теги php. Вставьте следующий код в кодовую панель, и вы получите другую ошибку (я не внес никаких других изменений в ваш код):

<?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>";

    }
}

}
?>

Затем внесите изменения из этого

$xml = this->twitterCapture(); 

до

$xml = $this->twitterCapture();

и ошибки волшебным образом исчезнут.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...