<?php
/*
<tr class="nextEpInfo">
<td width="160" align="right" nowrap="" class="nextEpInfo">Season: </td>
<td class="nextEpInfo" width="300">4</td>
</tr>
*/
$url = 'http://next-episode.net/the-good-wife';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch,CURLOPT_ENCODING, 1);
curl_setopt( $ch, CURLOPT_REFERER, $url );
$content = curl_exec ($ch);
//echo $content;
$matches = array();
preg_match_all( '/class="nextEpInfo">(.+):<\/td>\s*<td[^>]*>(\d*)</', $content, $matches );
print_r( $matches );
或类似的,这是最简单的,只要网站所有者不更改字符串即可。使用 xpath 或其他 xml/html 解析器可能是两个字符串匹配的开销,并且如果站点上的内容发生更改,可能会以相同的方式制动。