从HTML PHP中提取图库ID [关闭]

I have a variable named $html:

$html = '<li class="col">[gallery_id=234]</li>';

I want to get gallery_id (in this case - 234) into another variable from $html.

Easy. Just use regex with preg_match:

$html = '<li class="col">[gallery_id=234]</li>';
preg_match("/\[gallery_id=([0-9].*)\]/is", $html, $matches);

echo '<pre>';
print_r($matches);
echo '</pre>';

I have that print_r in there for debugging/illustration purposes. It would return the following:

Array
(
    [0] => [gallery_id=234]
    [1] => 234
)

Then to access the result you want, just do this:

echo $matches[1];

The returned value will be:

234

$html = '<li class="col">[gallery_id=234]</li>';
preg_match('!\d+!', $html, $var);
echo $var[0]; //echoes 234