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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵