这个用于Tumblr到网站的XML / PHP代码有什么问题吗?

时间:2011-04-27 19:12:54

标签: php xml web linker tumblr

我正在尝试将tumblr Feed链接到网站。我找到了这段代码(正如你所看到的,必须先用它来打破它,因为它甚至没有在这篇文章中正确格式化):

    <?php
$request_url = “http://thewalkingtree.tumblr.com/api/read?type=post&start=0&num=1”;
$xml = simplexml_load_file($request_url);
$title = $xml->posts->post->{‘regular-title’};
$post = $xml->posts->post->{‘regular-body’};
$link = $xml->posts->post[‘url’];
$small_post = substr($post,0,320);
echo ‘<h1>’.$title.’</h1>’;
echo ‘<p>’.$small_post.’</p>’;
echo “…”;
echo “</br><a target=frame2 href=’”.$link.”’>Read More</a>”; 
?>

And i inserted the tumblr link that I will be using.  When I try to preview my HTML, i get a bunch of messed up code that reads as follows:

posts->post->{'regular-title'}; $post = $xml->posts->post->{'regular-body'}; $link = $xml->posts->post['url']; $small_post = substr($post,0,320); echo '
'.$title.'

'; echo '
'.$small_post.'

'; echo "…"; echo "Read More"; ?>

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

那是PHP,而不是HTML。在将其提供给Web浏览器之前,您需要使用PHP解析器对其进行处理。

...它也应该被重写,以便它可以缓存远程数据,并在将数据注入HTML文档之前转义特殊字符。