Home > Web Front-end > HTML Tutorial > PHP regularly matches divs with classes in HTML and selects the content_html/css_WEB-ITnose

PHP regularly matches divs with classes in HTML and selects the content_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:50:59
Original
1219 people have browsed it

<div class="chartInfo">				                                <div class="line"></div>                                <div class="tideTable">                    <strong>潮汐表</strong><span style="font-size:12px;font-weight:lighter;margin-left:-20px;">数据仅供参考</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></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>时区:-1000 (东10区)  潮高基准面:在平均海平面下174CM</h2>					                </div>                <div class="chart">					<!--<img src="http://www.cnss.com.cn/statics/images/cnss/tide/tide.jpg" width="600" height="350" title="" alt="" /> -->                	                </div>                           </div>
Copy after login
这是源程序里边的一部分,为了容易看懂,删减了一大部分,只取<span style="font-family: Arial, Helvetica, sans-serif;"><div class="tideTable"> div块中的内容</span>
Copy after login
<span style="font-family: Arial, Helvetica, sans-serif;">首页先用file_get_content或curl获取内容部分,我用的是curl。</span>
Copy after login
<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>
Copy after login
<span style="font-family:Arial, Helvetica, sans-serif;">这样就可以了,不多解释,懂PHP的看代码,打印看一下效果。</span>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template