dongya6381 2016-01-27 00:54
浏览 29
已采纳

为什么一个preg_match工作而另一个工作

I haven't worked with preg_match() too terribly much but I can not figure out why searching for 1 div like this:

$div = '<div class="ipsPageHeader ipsClearfix">';
preg_match("/".$div."(.*?)<\/div>/", $html, $matches); $content=md5($matches[0]);

But when I try to search for a div different div like this:

$div = '<div class="cPost_contentWrap ipsPad">';
preg_match("/".$div."(.*?)<\/div>/", $html, $matches); $content=md5($matches[0]);

It gives me this error message:

Notice: Undefined offset: 0 in C:\xampp\htdocs\Freelancer\citrix\steam.php on line 33

If you're curious what page I'm pulling from it's Here

Basicaly, I'm taking the top post of this page to save and compare later to see if there have been changes

  • 写回答

1条回答 默认 最新

  • duande1985 2016-01-27 01:05
    关注

    On that particular page, there is no <div class="cPost_contentWrap ipsPad">, only <div class='cPost_contentWrap ipsPad'>. Notice that the one on the page uses single-quotes, while your regular expression uses double-quotes, meaning that the characters don't match and the search returns no results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器