preg_split unexpected behavior

前端 未结 3 1451
囚心锁ツ
囚心锁ツ 2021-01-27 11:47

I use preg_split as the following:

I ex

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 12:29

    You have to add delimiters to your regex like this:

    
    

    Output:

    Array ( [0] => 99 [1] => 14 )
    

    EDIT:

    The question why OP got the entire string back in the array is simple! If you read the manual here: http://php.net/manual/en/function.preg-split.php

    And take a quick quote from there under notes:

    Tip If matching fails, an array with a single element containing the input string will be returned.

提交回复
热议问题