php preg_match为什么它在地球上不起作用?

this is just so bang head on wall situation. this pattern works perfectly in javascript. and i have no idea what to do.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yugioh.wikia.com/wiki/List_of_Yu-Gi-Oh!_BAM_cards'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$chHtml = curl_exec($ch);
curl_close($ch);
$patt = '/<table class="wikitable sortable card-list">[\s\S]*?<\/table/im'; //////////////this 
preg_match($patt, $chHtml, $matches);

is the problem line

if i make it greedy

[\s\S]*

it works fine but it goes till the last

There is nothing wrong with the pattern, the problem is that you need a larger backtrack limit than the default.

Explaining:

In regex problems like that always check for errors using the preg_last error().

If you use it in the specific response from the site you submitted, since this is a resource problem and smaller texts do not raise the error, you will see that you are getting a PREG_BACKTRACK_LIMIT_ERROR.

Solution:

To overcome this limit you can raise it with the following in the start of your script:

ini_set ('pcre.backtrack_limit', 10000000);