2011-04-27 62 views
-1

我在嘗試將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

回答

1

這是PHP,而不是HTML。您需要先使用PHP解析器處理它,然後才能將其發送到Web瀏覽器。

...它也應該重寫,以便它可以緩存遠程數據,並在將數據注入HTML文檔之前轉義特殊字符。