PHP Extract numbers from a string

前端 未结 8 1499
傲寒
傲寒 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:26

    You can use this:

    // $str holds the string in question
    if (preg_match('/(\d+)to(\d+)/', $str, $matches)) {
        $number1 = $matches[1];
        $number2 = $matches[2];
    }
    

提交回复
热议问题