1 <?php 2 $str=<<<TXT 3 <table><thead><tr><th>種類</th><th>即期買入</th><th>即期賣出</th><th>銀行買進</th><th>銀行賣出</th></tr></thead><tbody><tr><td>美金 USD</td><td>30.79</td><td>30.89</td><td>30.49</td><td>31.035</td></tr><tr><td>日圓 JPY</td><td>0.2714</td><td>0.2754</td><td>0.2654</td><td>0.2764</td></tr><tr><td>歐元 EUR</td><td>34.83</td><td>35.23</td><td>34.58</td><td>35.48</td></tr><tr><td>人民幣 CNY</td><td>4.456</td><td>4.506</td><td>4.377</td><td>4.585</td></tr><tr><td>港幣 HKD</td><td>3.917</td><td>3.977</td><td>3.847</td><td>3.997</td></tr><tr><td>英鎊 GBP</td><td>39.05</td><td>39.55</td><td>-</td><td>-</td></tr><tr><td>瑞士法郎 CHF</td><td>30.77</td><td>31.21</td><td>-</td><td>-</td></tr><tr><td>澳幣 AUD</td><td>22.17</td><td>22.37</td><td>-</td><td>-</td></tr><tr><td>紐幣 NZD</td><td>21.09</td><td>21.29</td><td>-</td><td>-</td></tr><tr><td>新加坡幣 SGD</td><td>22.43</td><td>22.63</td><td>-</td><td>-</td></tr><tr><td>加拿大幣 CAD</td><td>22.93</td><td>23.13</td><td>-</td><td>-</td></tr><tr><td>南非幣 ZAR</td><td>2.129</td><td>2.249</td><td>-</td><td>-</td></tr></tbody> 4 TXT; 5 6 preg_match_all(\'/<td(.*?)>(.*?)<\/td>/s\', $str, $matches); 7 $data = $matches[2]; 8 for($i=0,$len=count($data); $i<$len; $i=$i+4){ 9 10 echo $data[$i].$data[$i+1].$data[$i+2].$data[$i+3]; 11 12 } 13 14 ?>