PHP extract all whole numbers into an array

前端 未结 4 1119
清酒与你
清酒与你 2021-01-28 15:58

I have following string:

15 asdas 26 dasda 354 dasd 1

and all that i want is to extract all numbers from it into an array, so it will looks li

4条回答
  •  滥情空心
    2021-01-28 16:43

    You can use preg_match_all():

    $string = '15 asdas 26 dasda 354 dasd 1';
    preg_match_all('/\b(\d+)\b/', $string, $numbers);
    
    var_dump($numbers[1]);
    

提交回复
热议问题