-1
我在尝试从我的网站的标题中获取我的推文时使用了一个来自JavaScript标记的ext PHP文件 - 我在PHP文件中包含了标题引用,输出为最后一行是javascript包含回声。从ext JavaScript文件引用PHP
<?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))";
?>
'latest_tweet'是一个PHP函数,而不是一个JavaScript函数。这种方式不能用JavaScript调用PHP函数。你为什么不直接用PHP输出内容? 'echo latest_tweet('mikedeveloper',0);'。 – 2012-03-07 21:02:31
我想让我的JavaScript和PHP独立于标记。 – 2012-03-07 21:12:57
但是'document.write(...)'似乎是不必要的......我想这取决于你如何包含这个文件。如果在文档加载后调用document.write,它将覆盖当前文档。 – 2012-03-07 21:16:23