通过Geocode解析Twitter提要无法显示状态链接

时间:2012-02-04 17:16:25

标签: php xml twitter

我目前正在使用地理编码解析Twitter推文并使用php显示它们。但目前我无法显示推文的链接。

但在XML中,它是feed-> entry->

<link type="text/html" href="http://twitter.com/OFFICIALGRINZ/statuses/165838159928762368" rel="alternate" >

是否可以从此标记内访问网址?

这是我的代码。

<?php
 $tabTitle = ' | Twitter';
$pageIntroductionHeading = 'Twitter';
$pageIntroductionContent = 'Twitter';
$column1Heading = 'London';
$column2Heading = 'New York';
$column3Heading = 'Paris';

require_once 'header.php';
 require_once 'navigationMenu.php';

 ?>

<?php require_once 'getWeather.php'; ?>
 <?php require_once 'getExchangeRates.php'; ?>

 <?php require_once 'pageIntroduction.php'; ?>


 <div id="obsah" class="content box">
<div class="in">
    <div class="shadow">
        <img src="./img/threeCities.jpg" alt="Three Cities Banner" title="Three Cities" class="thumb" />
    </div>
    <ul class="columns">
        <li class="col1">
            <h3><?php
if (isset($column1Heading)) {
echo $column1Heading;
}
?></h3>
            <p>

              <?php 
               $feed = simplexml_load_file ('http://search.twitter.com/search.atom?geocode=51.5069999695%2C-0.142489999533%2C10.0mi%22london%22&lang=en&rpp=5');
                if ($feed){foreach ($feed->entry as $item) {

                         echo '<a href=\'' . $item->author->uri. '\'>' . $item->title .         '</a>', '</br>' . $item->published, '</br>';
                    }
                    }
                    else echo "Cannot find Twitter feed!"
                     ?>


            </p>
        </li>
        <li class="col2">

        </li>
    </ul>
    <div class="clear"></div>
</div>
    <?php require_once 'footer.php'; ?>

1 个答案:

答案 0 :(得分:0)

您可以使用DomDocument Parser和DomXPath来访问您的链接。

$dom = new DomDocument();
$dom->load('yourfeed.xml');
$xpath = new DomXPath($dom);
$links = $xpath->query('/feed/entry/link'); // returns a DomNodeList with 0 or more elements
foreach ($links as $link)
{
    // $link->getAttribute('href');
}

此代码未经测试。