如何在PHP中从字符串中获取数字


How to get a number out of a string in PHP

我有以下字符串

Casas (3)

我想把数字三去掉。

在Jquery中,我使用这个regex

regExp = /'(([^)]+)')/;

但我不知道如何在PHP 中做到这一点

提前感谢

您可以尝试以下操作:

<?php 
$text = 'Casas (3)';
preg_match('#'((.*?)')#', $text, $match);
print $match[1];
?>

希望能有所帮助。。

试试这个

$str = "Casas (3)";
preg_match_all('!'d+!', $str, $matches);
print_r($matches);

将preg_match与正则表达式一起使用

$f = 'Casas (3)';
preg_match('/'(([^)]+)')/', $f, $fr)
echo $fr[1];