时间:2021-07-01 10:21:17 帮助过:2人阅读
/**
* @param $str
*
* @return string
*/
function getValue($str)
{
return preg_match('/(?:\D)(\d{8})(?:\D)/', $str, $matches) ? $matches[1] : '';
}
$arrStr = [
'10208899', //有
'#10208899', //有
'#test^10208899', //有
'#ff1020889900',//无
'#0010208899',//无
'#1020^10208899a',//有
'#5566880&10208899f',//有
'test?#10208899',//有
'#10208899.'//有
];
foreach ($arrStr as $i => $str) {
$value = getValue($str);
echo "$i\t{$str}\t\t=>\t{$value}\n";
}
0 10208899 =>
1 #10208899 =>
2 #test^10208899 =>
3 #ff1020889900 =>
4 #0010208899 =>
5 #1020^10208899a => 10208899
6 #5566880&10208899f => 10208899
7 test?#10208899 =>
8 #10208899. => 10208899
function getValue($str)
{
return preg_match('/(?:^
------解决思路----------------------
\D)(\d{8})(?:\D
------解决思路----------------------
$)/', $str, $matches) ? $matches[1] : '';
}
0 10208899 => 10208899
1 #10208899 => 10208899
2 #test^10208899 => 10208899
3 #ff1020889900 =>
4 #0010208899 =>
5 #1020^10208899a => 10208899
6 #5566880&10208899f => 10208899
7 test?#10208899 => 10208899
8 #10208899. => 10208899