我有一个字符串:
<div id="post_message_957119941">
我想使用preg_match
从此字符串中仅获取数字(957119941)。
答案 0 :(得分:23)
这不应该太难。
$str = '<div id="post_message_957119941">';
if ( preg_match ( '/post_message_([0-9]+)/', $str, $matches ) )
{
print_r($matches);
}
输出:
Array ( [0] => post_message_957119941 [1] => 957119941 )
因此,所需的结果将始终位于:$matches[1]
这就是你需要的吗?