如何在PHP中从字符串中获取数字
我有下面的字符串如何在PHP中从字符串中获取数字,php,Php,我有下面的字符串 Casas (3) 我想从中得到第三个 在Jquery中,我使用这个正则表达式 regExp = /\(([^)]+)\)/; 但我不知道如何在PHP中做到这一点 提前感谢试试这个 $str = "Casas (3)"; preg_match_all('!\d+!', $str, $matches); print_r($matches); 您可以尝试以下方法: <?php $text = 'Casas (3)'; preg_match('#\((.*?)\)#',
Casas (3)
我想从中得到第三个
在Jquery中,我使用这个正则表达式
regExp = /\(([^)]+)\)/;
但我不知道如何在PHP中做到这一点
提前感谢试试这个
$str = "Casas (3)";
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
您可以尝试以下方法:
<?php
$text = 'Casas (3)';
preg_match('#\((.*?)\)#', $text, $match);
print $match[1];
?>
希望它有帮助。使用preg_匹配正则表达式
$f = 'Casas (3)';
preg_match('/\(([^)]+)\)/', $f, $fr)
echo $fr[1];
只是出于好奇:除了绳子还有什么区别?如果答案=none->这将是一个重复啊..我无法检查..因为有很多赛前问题的答案可用。。。