php正则匹配问题请教!

kukala 发布于 2013/07/23 11:56
阅读 585
收藏 0
PHP
preg_match("#<tr>
    <td colspan=\"2\" align=\"left\" class=\"bt\"><h1>来源:快播QVOD</h1>
        (.*?)</td>
  </tr>#s",$content, $arr);

分别采集:

http://www.fensizy.com/Details_zy.asp?name_id=51419http://www.fensizy.com/Details_zy.asp?name_id=15012

能够匹配到前者,但是匹配不到后者,请大家帮忙看看!
array(2) {
  [0] => string(2399) "<tr>
    <td colspan="2" align="left" class="bt"><h1>来源:快播QVOD</h1>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><ul>
              <li><a href="/play/?play_51419_1_1.html" target="_blank">第01集$qvod://138795798|0EF8EFD7A1C4C45E6DFB2EAC7B413061EA145013|打工吧!魔王大人01.mp4|</a></li><li><a href="/play/?play_51419_1_2.html" target="_blank">第02集$qvod://128317057|FE8B87C3DAD083F9F2CA8ABD2E22827CA31F60CF|打工吧!魔王大人02.mp4|</a></li><li><a href="/play/?play_51419_1_3.html" target="_blank">第03集$qvod://147411491|DE2946873C0668A11AB8F6363FEE60BFC41D113A|打工吧!魔王大人03.mp4|</a></li><li><a href="/play/?play_51419_1_4.html" target="_blank">第04集$qvod://148130787|21EFC67ACCD8CDAC03D5B00A3AD09023399DDB08|打工吧!魔王大人04.mp4|</a></li><li><a href="/play/?play_51419_1_5.html" target="_blank">第05集$qvod://189351178|85C9503BF2A21F98A73BEC31F56D6C7481BE5101|打工吧!魔王大人05修正.mp4|</a></li><li><a href="/play/?play_51419_1_6.html" target="_blank">第06集$qvod://142197922|57AB37E4158E2DC9ECF39AE2317D7BD390A4A4A8|_打工吧!魔王大人06.mp4|</a></li><li><a href="/play/?play_51419_1_7.html" target="_blank">第07集$qvod://151771318|FDC25D1747E55BD218F311EBAE3477F16A3DC473|打工吧!魔王大人07修正.mp4|</a></li><li><a href="/play/?play_51419_1_8.html" target="_blank">第08集$qvod://154328698|C2747F6A8271EA783F57C92782451A95AB35E252|打工吧!魔王大人08.mp4|</a></li><li><a href="/play/?play_51419_1_9.html" target="_blank">第09集$qvod://137892520|322B2308DFD25F433E9F2E61D9F2E8EFA4701309|打工吧!魔王大人09.rmvb|</a></li><li><a href="/play/?play_51419_1_10.html" target="_blank">第10集$qvod://177274814|E7474DC62251D81B8347DFDBF94A5E11AC26C646|打工吧!魔王大人10.mp4|</a></li><li><a href="/play/?play_51419_1_11.html" target="_blank">第11集$qvod://152947281|96241CCCC208C4E1FED275C1D8B0CCD1F56110D0|打工吧魔王大人11.mp4|</a></li><li><a href="/play/?play_51419_1_12.html" target="_blank">第12集$qvod://164166887|FB476AEECCF644F69D571C68B3FAEABE483AE22D|打工吧!魔王大人12.mp4|</a></li><li><a href="/play/?play_51419_1_13.html" target="_blank">第13集$qvod://155772681|2F41B4C5F7678B6762314AB8AA5AB381832A2F50|打工吧!魔王大人13.mp4|</a></li>
            </ul></td>
          </tr>
      </table></td>
  </tr>"
  [1] => string(2299) "<table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><ul>
              <li><a href="/play/?play_51419_1_1.html" target="_blank">第01集$qvod://138795798|0EF8EFD7A1C4C45E6DFB2EAC7B413061EA145013|打工吧!魔王大人01.mp4|</a></li><li><a href="/play/?play_51419_1_2.html" target="_blank">第02集$qvod://128317057|FE8B87C3DAD083F9F2CA8ABD2E22827CA31F60CF|打工吧!魔王大人02.mp4|</a></li><li><a href="/play/?play_51419_1_3.html" target="_blank">第03集$qvod://147411491|DE2946873C0668A11AB8F6363FEE60BFC41D113A|打工吧!魔王大人03.mp4|</a></li><li><a href="/play/?play_51419_1_4.html" target="_blank">第04集$qvod://148130787|21EFC67ACCD8CDAC03D5B00A3AD09023399DDB08|打工吧!魔王大人04.mp4|</a></li><li><a href="/play/?play_51419_1_5.html" target="_blank">第05集$qvod://189351178|85C9503BF2A21F98A73BEC31F56D6C7481BE5101|打工吧!魔王大人05修正.mp4|</a></li><li><a href="/play/?play_51419_1_6.html" target="_blank">第06集$qvod://142197922|57AB37E4158E2DC9ECF39AE2317D7BD390A4A4A8|_打工吧!魔王大人06.mp4|</a></li><li><a href="/play/?play_51419_1_7.html" target="_blank">第07集$qvod://151771318|FDC25D1747E55BD218F311EBAE3477F16A3DC473|打工吧!魔王大人07修正.mp4|</a></li><li><a href="/play/?play_51419_1_8.html" target="_blank">第08集$qvod://154328698|C2747F6A8271EA783F57C92782451A95AB35E252|打工吧!魔王大人08.mp4|</a></li><li><a href="/play/?play_51419_1_9.html" target="_blank">第09集$qvod://137892520|322B2308DFD25F433E9F2E61D9F2E8EFA4701309|打工吧!魔王大人09.rmvb|</a></li><li><a href="/play/?play_51419_1_10.html" target="_blank">第10集$qvod://177274814|E7474DC62251D81B8347DFDBF94A5E11AC26C646|打工吧!魔王大人10.mp4|</a></li><li><a href="/play/?play_51419_1_11.html" target="_blank">第11集$qvod://152947281|96241CCCC208C4E1FED275C1D8B0CCD1F56110D0|打工吧魔王大人11.mp4|</a></li><li><a href="/play/?play_51419_1_12.html" target="_blank">第12集$qvod://164166887|FB476AEECCF644F69D571C68B3FAEABE483AE22D|打工吧!魔王大人12.mp4|</a></li><li><a href="/play/?play_51419_1_13.html" target="_blank">第13集$qvod://155772681|2F41B4C5F7678B6762314AB8AA5AB381832A2F50|打工吧!魔王大人13.mp4|</a></li>
            </ul></td>
          </tr>
      </table>"
}

 

加载中
0
Tuesday
Tuesday
preg_match("#</h1>(.*</table>)</td>#isU",$content, $arr);
k
kukala
还是匹配不了啊! = =!
胖胖
胖胖
要联系方式啊啊啊啊啊!!!!!
0
Tuesday
Tuesday

$data = ' <td colspan="2" align="left" class="bt"><h1>来源:快播QVOD</h1>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><ul>
              <li><a href="/play/?play_15012_1_1.html" target="_blank">第01集$qvohref="/play/?play_15012_1_713.html" target="_blank">第713集$qvod://127683718|DA9D74D72FF5FC4D64CA52F33B950A3635F38EAA|名偵探柯南713.rmvb|</a></li>
            </ul></td>
          </tr>
      </table></td>
  </tr>';
 
  preg_match("#</h1>(.*</table>)</td>#isU",$data, $arr);
 
  print_r($arr[1]);

测试通过..

k
kukala
只能匹配到前者,后者匹配不了!请看下!
0
开源中国首席煤工
开源中国首席煤工

试下dom解析,我测试都可以抓取到,不知道是不是你想要的结果。

header('Content-type:text/html;charset=utf-8');
$ch=curl_init('http://www.fensizy.com/Details_zy.asp?name_id=15012');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
$result=curl_exec($ch);
include 'SimpleHtmlDom.class.php';
$html=str_get_html($result);
$re=$html->find('.bt ul',0)->outertext;
var_dump($re);

k
kukala
SimpleHtmlDom是可以实现,但$rs[0]里的数据并不一定是所要的数据! 所以最好能正则来实现!
0
Tuesday
Tuesday

$data = file_get_contents('http://www.fensizy.com/Details_zy.asp?name_id=15012');

$data = mb_convert_encoding($data, 'utf-8', 'gbk');
  preg_match_all("#</h1>.*(<table.*<ul>.*://.*</ul>.*</table>)#isU",$data, $arr);
 
  print_r($arr[1]);
  print_r($arr[2]);

k
kukala
你可以匹配到吗? 我这里还是匹配不到,是不是环境的关系啊?是win php5.2.0 apache2.2.4
0
k
kukala

请大家帮帮忙!

k
kukala
我都测试过了,匹配不到内容,不知道是什么原因?
陨落人间
陨落人间
楼上几个热心的帮你搞定了,还要怎么样呢?
0
cfrs2005
cfrs2005
http://www.80aj.com/2618.html  
0
k
kukala

非常感谢,我测试了下,但还是匹配不到内容,估计是我的环境问题了!

返回顶部
顶部