1

我正在使用 cURL 抓取一个站点并返回输出,然后将其放入 preg_match() 函数以检索某些内容。当我尝试抓取以下内容时,它没有显示任何内容。

preg_match('/var b=new (.*)var p=new /i', $bountyHTML, $ting);
$chou = $ting[1];
echo $chou;

我试图从中抓取的 $bountyHTML 中的部分如下所示:

<script>
    function fsb(x) {
      var b=new Array(101,55,100,99,52,49,57,50,54,56,51,55,54,49,51,50,101,50,49,50,100,54,49,97,50,53,52,99,100,57,54,53,51,100,49,54,55,38,101,101,49,104,61,101,61,50,50,49,56,99,110,111,78,50,109,114,111,102,38,52,61,100,101,55,105,95,98,116,115,105,51,108,48,116,105,97,104,63,112,104,52,112,97,49,46,121,55,56,52,101,102,54,50,116,110,117,52,111,98,47,101,54,57,52,57,101,53,99,98,102,56,48,98,51);
      var p=new Array(1,0,1,0,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,1,0,1,1,1,1,0,0,1,0,1,0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,0,1,1,0,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);       
      var bountyForm = document.getElementById('bountyForm');
      bountyForm.action = c(b,p) + x;
      return true;
    }
  </script>

任何想法为什么它不会返回任何东西?谢谢!

4

1 回答 1

0
preg_match('/var b=new (.*)var p=new /is', $bountyHTML, $ting);

http://php.net/manual/en/reference.pcre.pattern.modifiers.php

s (PCRE_DOTALL) 如果设置了此修饰符,则模式中的点元字符匹配所有字符,包括换行符。没有它,换行符被排除在外。这个修饰符等价于 Perl 的 /s 修饰符。诸如 [^a] 之类的否定类始终匹配换行符,与此修饰符的设置无关。

于 2013-09-17T23:28:15.380 回答