Tumblr到网站的XML/PHP代码是否有问题?
我正在尝试将tumblr提要链接到一个网站。我发现了这段代码(正如你所看到的,这段代码一定有问题,因为它在这篇文章中的格式都不正确):Tumblr到网站的XML/PHP代码是否有问题?,php,xml,web,linker,tumblr,Php,Xml,Web,Linker,Tumblr,我正在尝试将tumblr提要链接到一个网站。我发现了这段代码(正如你所看到的,这段代码一定有问题,因为它在这篇文章中的格式都不正确): posts->post->{'regular-title'}; $post=$xml->posts->post->{'regular-body'}; $link=$xml->posts->post['url']; $small_post=substr($post,0320); 回显“.$title.”; 回显“”.$small_post.“”; 回声“…”; 回
posts->post->{'regular-title'};
$post=$xml->posts->post->{'regular-body'};
$link=$xml->posts->post['url'];
$small_post=substr($post,0320);
回显“.$title.”;
回显“”.$small_post.“”;
回声“…”;
回声“”;
?>
我插入了我将要使用的tumblr链接。当我尝试预览HTML时,我得到了一堆乱七八糟的代码,如下所示:
posts->post->{'regular-title'}$post=$xml->posts->post->{'regular-body'}$link=$xml->posts->post['url']$小型邮政=substr($post,0320);回声'
“.$title。”
'; 回声'
“.$small_post”
'; 回声“…”;回声“阅读更多”?>
任何帮助都将不胜感激。谢谢大家! 那是PHP,不是HTML。在将其交付到web浏览器之前,需要使用PHP解析器进行处理 …还应该重写它,以便它可以缓存远程数据,并在将数据注入HTML文档之前转义特殊字符
<?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"; ?>