dongxiong5546 2011-07-23 00:35
浏览 42
已采纳

为什么这个PHP代码段不起作用?

In localhost (using Wamp on windows). I'm trying to use this:

<?
$xml = simplexml_load_file(‘http://stocklamp.tumblr.com/api/read/xml’);
$posts = $xml->xpath(“/tumblr/posts/post[@type=’regular’]”);
foreach($posts as $post) {?>  
<?echo $post[‘id’];?>
<?echo $post[‘url-with-slug’];?>”>
<?echo $post->{‘regular-title’};?>
<?echo $post->{‘regular-body’};?>
<?echo date(“jS D M, H:i”,strtotime($post[‘date’]));?>
<?}?>

When trying, all I see is this on my site:

xpath(“/tumblr/posts/post[@type=’regular’]”); foreach($posts as $post) { ?> ”> {‘regular-title’};?> {‘regular-body’};?>

I found the snippet here:

http://stocklamp.tumblr.com/post/274675902/putting-your-tumblr-posts-on-your-websites-the-easy-way

Edit: fixed. Now I'm getting

Parse error: syntax error, unexpected ':' in C:\wamp\www..\index.php on line 52

and it is this line:

$xml = simplexml_load_file(‘http://stocklamp.tumblr.com/api/read/xml’);

I keep getting this error: http://codepad.org/7f1IejIG

Okay. Now I go that fixed, but how do I get the posts by tag?

changing 'type=...' doesn't work.

$posts = $xml->xpath("/tumblr/posts/post[@type='file']");
  • 写回答

3条回答 默认 最新

  • duanpuchun5275 2011-07-23 01:19
    关注

    The last problem is to resolve is that the API XML url provided on the blog is not right. The following works:

    <?php
    $xml = simplexml_load_file('http://stocklamp.tumblr.com/api/read/'); // No /xml
    $posts = $xml->xpath('/tumblr/posts/post[@type="regular"]');
    foreach($posts as $post) {?>  
    <?echo $post['id'];?>
    <?echo $post['url-with-slug'];?>”>
    <?echo $post->{'regular-title'};?>
    <?echo $post->{'regular-body'};?>
    <?echo date("jS D M, H:i",strtotime($post['date']));?>
    <?}?>
    

    http://jfcoder.com/test/tumblrtest.php

    EDIT

    Try running this code without the tags interspersed:

    <?php
    $xml = simplexml_load_file('http://stocklamp.tumblr.com/api/read/'); // No /xml
    $posts = $xml->xpath('/tumblr/posts/post[@type="regular"]');
    foreach($posts as $post) {  
        echo $post['id'];
        echo $post['url-with-slug'];
        echo $post->{'regular-title'};
        echo $post->{'regular-body'};
        echo date("jS D M, H:i",strtotime($post['date']));
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用