PHP Extract numbers from a string

前端 未结 8 1496
傲寒
傲寒 2021-01-28 08:23

I want to extract numbers from a string in PHP like following :

if the string = \'make1to6\' i would like to extract the numeric charac

8条回答
  •  心在旅途
    2021-01-28 08:39

    You could use preg_match_all to achive this:

    function getNumbersFromString($str) {
        $matches = array();
        preg_match_all("/([0-9]+)/",$str,$matches);
        return $matches;
    }
    $matches = getNumbersFromString("hej 12jippi77");
    

提交回复
热议问题