我在尝试使用从JavaScript标记引用的扩展PHP文件来获取我的网站标题上的推文时遇到了一些麻烦 - 我在PHP文件中包含了标头引用,并且输出作为最后一行是javascript包含回声。
<?php
Header("content-type: application/x-javascript");
//Get Latest Tweet
function latest_tweet($username,$tweetnumber){
$url = "http://search.twitter.com/search.atom?q=from:$username&rpp=10";
$xml = simplexml_load_file($url);
$tweettitle = $xml->entry[$tweetnumber]->title;
$mytweet = $xml->entry[$tweetnumber]->content;
$firstChar = substr($tweettitle, 0, 1);
//Exclude @ replies
if($firstChar == "@"){
//If this tweet is an @ reply move on to the previous one
while ($firstChar == "@"){
$tweetnumber++;
$tweettitle = $xml->entry[$tweetnumber]->title;
$mytweet = $xml->entry[$tweetnumber]->content;
$firstChar = substr($tweettitle, 0, 1);
if($firstChar != "@"){
//If the previous tweet is not an @ reply output it
return $mytweet;
}
}
} else {
//If first tweet is not an @ reply output it
return $mytweet;
}
}
//End Get Latest Tweet
//output
echo "document.write(latest_tweet('mikedeveloper', 0))";
?>
答案 0 :(得分:1)
由于latest_tweet
是一个PHP函数,你必须从PHP调用它,但是你试图从javascript调用它。试试这个:
echo "document.write('" . latest_tweet('mikedeveloper', 0) . "')";