📜  php 从字符串中获取数字 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:30.830000             🧑  作者: Mango

代码示例6
function get_numerics ($str) {
    preg_match_all('/\d+/', $str, $matches);
    return $matches[0];
}

// this function will return an array of number

$str = "3 dogs were running!";
echo (get_numerics($str)[0]); 

// output 3