Regular expression for extracting a number

后端 未结 4 1651
不思量自难忘°
不思量自难忘° 2020-12-22 08:45

I would like to be able to extract a number from within a string formatted as follows:

\"<[1085674730]> hello foo1, how are you doing?\"

I\'m a novice wit

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 08:58

    $subject = "<[1085674730]> hello foo1, how are you doing?";
    preg_match('/<\[(\d+)\]>/', $subject, $matches);
    

    $matches[1] will contain the number you are looking for.

提交回复
热议问题