使用preg_match从字符串中获取数字

use*_*679 11 php preg-match

我有一个字符串:

 <div id="post_message_957119941">
Run Code Online (Sandbox Code Playgroud)

我想从这个字符串中仅使用获取数字(957119941)preg_match.

w00*_*w00 23

这不应该太难.

$str = '<div id="post_message_957119941">';

if ( preg_match ( '/post_message_([0-9]+)/', $str, $matches ) )
{
    print_r($matches);
}
Run Code Online (Sandbox Code Playgroud)

输出:

Array ( [0] => post_message_957119941 [1] => 957119941 )

所以期望的结果总是在: $matches[1]

这就是你需要的吗?