PHP Extract numbers from a string

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

    You can use a regular expression as such, it should match exactly your specification:

    $string = 'make6to12';
    preg_match('{^.*?(?P\d{1,2})to(?P\d{1,2})}m', $string, $match);
    echo $match['before'].', '.$match['after']; // 6, 12
    

提交回复
热议问题