2012-03-09 40 views
0

我目前通過holidays.xmllogged_in.php表中。使一個值鏈接另一個

holidays.xml

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"> 
<channel> 
<item> 
     <title>Luxurious Jamaican holidays | 40% Discount On Accommodation - Book Now!</title> 
     <link>http://www.numyspace.co.uk/~cgel1/holidays/Jamaica.html</link> 
     <description>7 nights at The Golden Palm, Montego Bay travelling from Newcastle with Fly Jamaica</description> 
     <pubDate>Sun, 13 Feb 2011 11:58:17 GMT</pubDate> 
     <guid>http://www.numyspace.co.uk/~cgel1/holidays/Jamaica.html</guid> 
    </item> 
</channel> 
</rss> 

logged_in.php

 <?php 
// load the xml file into a simplexml instance variable 
$holiday = simplexml_load_file('holidays.xml'); 

// draw a table and column headers 
echo "<table border=\"0\">"; 
/* echo " <th>Title</td> 
     <th>Link</td> 
     <th>Description</td> 
     <th>Published Date</th>"; 
*/ 
// iterate through the item nodes displaying the contents 
foreach ($holiday->channel->item as $holiday) { 
    echo "<tr>"; 
    echo "<td>{$holiday->title}</td>"; 
    echo "<td>{$holiday->link}</td>"; 
    echo "<td>{$holiday->description}</td>"; 
    echo "<td>{$holiday->pubDate}</td>"; 
    echo "</tr>\n"; 
} 
echo "</table>"; 
?> 

我想echo "<td>{$holiday->link}</td>";是的echo "<td>{$holiday->title}</td>";一個鏈接,這樣的鏈接將是href和冠軍稱號。有沒有簡單的方法來做到這一點?

回答

2
echo "<td><a href=\"{$holiday->link}\">{$holiday->title}</a></td>"; 
+0

我幾乎在那裏,這工作完美的感謝。 – 2012-03-09 10:08:12

0

您可以在TD之前,將href添加錨點,就像這樣:

foreach ($holiday->channel->item as $holiday) { 
    echo "<tr>"; 
    echo "<a href='{$holiday->link}'><td>{$holiday->title}</td></a>"; 
    echo "<td>{$holiday->description}</td>"; 
    echo "<td>{$holiday->pubDate}</td>"; 
    echo "</tr>\n"; 
} 

我不會用SimpleXML熟悉,我聽說過,但從來沒有與它的工作,所以我不知道我所做的是否正確。

相關問題