Php 使用preg_匹配从字符串中获取数字
我有一个字符串:Php 使用preg_匹配从字符串中获取数字,php,preg-match,Php,Preg Match,我有一个字符串: <div id="post_message_957119941"> 我只想使用preg\u match从这个字符串中获取数字(957119941) 这应该不会太难 $str = '<div id="post_message_957119941">'; if ( preg_match ( '/post_message_([0-9]+)/', $str, $matches ) ) { print_r($matches); } $str='
<div id="post_message_957119941">
我只想使用
preg\u match
从这个字符串中获取数字(957119941) 这应该不会太难
$str = '<div id="post_message_957119941">';
if ( preg_match ( '/post_message_([0-9]+)/', $str, $matches ) )
{
print_r($matches);
}
$str='';
if(preg_match('/post_message([0-9]+)/',$str,$matches))
{
打印(匹配项);
}
输出:
Array([0]=>post\u message\u 957119941[1]=>957119941)
因此,所需的结果总是:$matches[1]
这就是你需要的吗?你试过我的正则表达式了吗?它对你有用吗?我不明白为什么这个问题因“不是真正的问题”而关闭。。。好吧:preg_match(“/\d+/”,“”,$match)将设置$match[0=>957119941]我需要多个字符串和数字,然后我需要用户
if(preg_match('/S([0-9]+)E([0-9]+)/,strtoupper($fileName),$matches))
这对我有用