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.

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

报告相同问题?

悬赏问题

  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题