-1

我正在尝试将 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 ‘&lt;h1>’.$title.’&lt;/h1>’;
echo ‘&lt;p>’.$small_post.’&lt;/p>’;
echo “…”;
echo “&lt;/br><a target=frame2 href=’”.$link.”’&gt;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"; ?>

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

4

1 回答 1

1

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

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

于 2011-04-27T19:15:14.597 回答