这个XML/PHP代码为Tumblr网站有什么问题吗?

问题描述:

我在尝试将tumblr订阅源链接到网站。我发现这个代码(正如你所看到的东西也必须随之被打破,因为它在这个岗位正确甚而不格式):这个XML/PHP代码为Tumblr网站有什么问题吗?

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

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

+0

什么不起作用? – justkt 2011-04-27 19:14:18

这是PHP,而不是HTML。您需要先使用PHP解析器处理它,然后才能将其发送到Web浏览器。

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