为什么一个 preg_match 有效而另一个无效

Why does one preg_match work but not the other

我没有使用 preg_match() 太多,但我不明白为什么要像这样搜索 1 div:

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

但是当我尝试像这样搜索 div 不同的 div 时:

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

它给我这个错误信息:

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

如果你想知道我从哪个页面中拉出 Here

基本上,我把这个页面的顶部post保存起来,稍后比较看是否有变化

在该特定页面上,没有 <div class="cPost_contentWrap ipsPad">,只有 <div class='cPost_contentWrap ipsPad'>。请注意,页面上的那个使用 single-quotes,而您的正则表达式使用 double-quotes,这意味着字符不匹配并且搜索 returns 没有结果。