<div class="chartInfo"> <div class="line"></div> <div class="tideTable"> <strong>潮汐表</strong><span style="font-size:12px;font-weight:lighter;margin-left:-20px;">數(shù)據(jù)僅供參考</span> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tbody><tr> <td width="100"><p><span>潮時 (hrs)</span></p></td> <td width="100"><p>00:58</p></td> <td width="100"><p>05:20</p></td> <td width="100"><p>13:28</p></td> <td width="100"><p>21:15</p><p><span>立即學習</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免費學習筆記(深入)</a>”;</p></td> </tr> <tr> <td><p><span>潮高 (cm)</span></p></td> <td width="100"><p>161</p></td> <td width="100"><p>75</p></td> <td width="100"><p>288</p></td> <td width="100"><p>127</p></td> </tr> </tbody></table> <h2>時區(qū):-1000 (東10區(qū)) 潮高基準面:在平均海平面下174CM</h2> </div> <div class="chart"> <!--<img src="http://www.cnss.com.cn/statics/images/cnss/tide/tide.jpg" style="max-width:90%" style="max-width:90%" title="" alt="" /> --> </div> </div>
這是源程序里邊的一部分,為了容易看懂,刪減了一大部分,只取<span style="font-family: Arial, Helvetica, sans-serif;"><div class="tideTable"> div塊中的內(nèi)容</span>
<span style="font-family: Arial, Helvetica, sans-serif;">首頁先用file_get_content或curl獲取內(nèi)容部分,我用的是curl。</span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span><span style="white-space:pre"> </span>$ch = curl_init();<span style="white-space:pre"> </span>curl_setopt($ch, CURLOPT_URL, $url);<span style="white-space:pre"> </span>curl_setopt($ch, CURLOPT_POST, 1);<span style="white-space:pre"> </span>curl_setopt( $ch, CURLOPT_HEADER, 0 );<span style="white-space:pre"> </span>curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );<span style="white-space:pre"> </span>curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );<span style="white-space:pre"> </span>$return = curl_exec( $ch );<span style="white-space:pre"> </span>curl_close( $ch );<span style="white-space:pre"> </span><span style="white-space:pre"> </span>$regex4="/<div class=\"tideTable\".*?>.*?<\/div>/ism";<span style="white-space:pre"> </span>if(preg_match_all($regex4, $return, $matches)){ <span style="white-space:pre"> </span> print_r($matches);<span style="white-space:pre"> </span>}else{<span style="white-space:pre"> </span>echo '0';<span style="white-space:pre"> </span>}</span>
<span style="font-family:Arial, Helvetica, sans-serif;">這樣就可以了,不多解釋,懂PHP的看代碼,打印看一下效果。</span>
PHP怎么學習?PHP怎么入門?PHP在哪學?PHP怎么學才快?不用擔心,這里為大家提供了PHP速學教程(入門到精通),有需要的小伙伴保存下載就能學習啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號