XML结构:
<channel>
<title>
</title>
<item>
<description>
<tbody>
<tr>
<td class="chart_stock_name">NUGT</td>
<td class="chart_stock_price">5.86</td>
<td class="chart_stock_change">+1.02</td>
<td class="chart_stock_prc">+(21.07%)</td>
</tr>
</description>
</item>
</channel>
代码:
$xml = simplexml_load_file($url);
for($i = 0; $i <= 6; $i++) {
$variablename = $xml->channel->item->description;
}
--
我需要获取 td 类中的每个值。我能做到的最好的办法是回显包含所有行的描述。
在 td 类中获取值的正确方法是什么?即“NUGT”
更新(完整的 XML):
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="/res/preview.xsl"?>
<rss version="2.0">
<channel>
<title>Price % Gainers</title>
<link>http://finance.yahoo.com/gainers?e=nq</link>
<description><![CDATA[The list of gainers by % in the NYSE]]></description>
<lastBuildDate>Mon, 01 Jul 2013 13:46:05 GMT</lastBuildDate>
<generator>Feed43 Proxy/1.0 (www.feed43.com)</generator>
<ttl>360</ttl>
<item>
<guid isPermaLink="false">e5a4b37b270cb65b3039e1d7c0152a88</guid>
<pubDate>Mon, 01 Jul 2013 13:46:05 GMT</pubDate>
<title>Stock Gainers</title>
<link>http://finance.yahoo.com/q?s=REMX</link>
<description><![CDATA[<table class="chart_stock">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Change</th>
<th>% Chg</th>
</tr>
</thead>
<tbody><tr><td class="chart_stock_name">REMX</td><td class="chart_stock_price">39.00</td><td class="chart_stock_change">+29.51</td><td class="chart_stock_prc">+(310.96%)</td></tr><tr><td class="chart_stock_name">GDXJ</td><td class="chart_stock_price">36.99</td><td class="chart_stock_change">+27.83</td><td class="chart_stock_prc">+(303.82%)</td></tr><tr><td class="chart_stock_name">GEX</td><td class="chart_stock_price">51.45</td><td class="chart_stock_change">+36.23</td><td class="chart_stock_prc">+(238.04%)</td></tr><tr><td class="chart_stock_name">LVB</td><td class="chart_stock_price">35.04</td><td class="chart_stock_change">+4.61</td><td class="chart_stock_prc">+(15.15%)</td></tr><tr><td class="chart_stock_name">NUGT</td><td class="chart_stock_price">6.36</td><td class="chart_stock_change">+0.50</td><td class="chart_stock_prc">+(8.48%)</td></tr><tr><td class="chart_stock_name">FWDI</td><td class="chart_stock_price">23.88</td><td class="chart_stock_change">+0.00</td><td class="chart_stock_prc">+(0.00%)</td></tr><tr><td class="chart_stock_name">LAS</td><td class="chart_stock_price">5.11</td><td class="chart_stock_change">+0.31</td><td class="chart_stock_prc">+(6.46%)</td></tr><tr><td class="chart_stock_name">WWAV-B</td><td class="chart_stock_price">16.10</td><td class="chart_stock_change">+0.90</td><td class="chart_stock_prc">+(5.92%)</td></tr><tr><td class="chart_stock_name">LPLT</td><td class="chart_stock_price">31.78</td><td class="chart_stock_change">+0.00</td><td class="chart_stock_prc">+(0.00%)</td></tr><tr><td class="chart_stock_name">P</td><td class="chart_stock_price">19.43</td><td class="chart_stock_change">+1.03</td><td class="chart_stock_prc">+(5.59%)</td></tr><tr><td class="chart_stock_name">MUX</td><td class="chart_stock_price">1.78</td><td class="chart_stock_change">+0.10</td><td class="chart_stock_prc">+(5.95%)</td></tr><tr><td class="chart_stock_name">NOK</td><td class="chart_stock_price">3.94</td><td class="chart_stock_change">+0.20</td><td class="chart_stock_prc">+(5.21%)</td></tr><tr><td class="chart_stock_name">AUQ</td><td class="chart_stock_price">4.59</td><td class="chart_stock_change">+0.22</td><td class="chart_stock_prc">+(5.03%)</td></tr><tr><td class="chart_stock_name">UWTI</td><td class="chart_stock_price">30.81</td><td class="chart_stock_change">+1.44</td><td class="chart_stock_prc">+(4.90%)</td></tr><tr><td class="chart_stock_name">DRD</td><td class="chart_stock_price">5.69</td><td class="chart_stock_change">+0.26</td><td class="chart_stock_prc">+(4.79%)</td></tr><tr><td class="chart_stock_name">AUO</td><td class="chart_stock_price">3.62</td><td class="chart_stock_change">+0.16</td><td class="chart_stock_prc">+(4.62%)</td></tr><tr><td class="chart_stock_name">SLVP</td><td class="chart_stock_price">11.88</td><td class="chart_stock_change">+0.52</td><td class="chart_stock_prc">+(4.58%)</td></tr><tr><td class="chart_stock_name">IAG</td><td class="chart_stock_price">4.38</td><td class="chart_stock_change">+0.18</td><td class="chart_stock_prc">+(4.16%)</td></tr><tr><td class="chart_stock_name">EGO</td><td class="chart_stock_price">6.42</td><td class="chart_stock_change">+0.24</td><td class="chart_stock_prc">+(3.88%)</td></tr><tr><td class="chart_stock_name">GNK</td><td class="chart_stock_price">1.63</td><td class="chart_stock_change">+0.00</td><td class="chart_stock_prc">+(0.00%)</td></tr><tr><td class="chart_stock_name">TKC</td><td class="chart_stock_price">14.98</td><td class="chart_stock_change">+0.61</td><td class="chart_stock_prc">+(4.24%)</td></tr><tr><td class="chart_stock_name">TAHO</td><td class="chart_stock_price">14.73</td><td class="chart_stock_change">+0.58</td><td class="chart_stock_prc">+(4.10%)</td></tr><tr><td class="chart_stock_name">BALT</td><td class="chart_stock_price">3.86</td><td class="chart_stock_change">+0.15</td><td class="chart_stock_prc">+(4.04%)</td></tr><tr><td class="chart_stock_name">TGEM</td><td class="chart_stock_price">19.01</td><td class="chart_stock_change">+0.72</td><td class="chart_stock_prc">+(3.94%)</td></tr><tr><td class="chart_stock_name">MMD</td><td class="chart_stock_price">18.69</td><td class="chart_stock_change">+0.70</td><td class="chart_stock_prc">+(3.89%)</td></tr></tbody>
</table>]]></description>
</item>
</channel>
</rss>