Tumblr 到网站的 XML/PHP 代码有问题吗?

发布于 2024-11-03 16:52:43 字数 1031 浏览 1 评论 0原文

我正在尝试将 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"; ?>

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

I am trying to link a tumblr feed to a website. I found this code (As you can see, something must be broken with it as it doesnt even format correctly in this post):

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

Any help would be appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2024-11-10 16:52:43

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

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

That is PHP, not HTML. You need to process it with a PHP parser before delivering it to a web browser.

… it should also be rewritten so it can cache the remote data, and escape special characters before injecting the data into an HTML document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文