Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中从字符串中获取数字_Php - Fatal编程技术网

如何在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->这将是一个重复啊..我无法检查..因为有很多赛前问题的答案可用。。。