preg_match to match substring of three numbers consecutively?
问题 I have a string $text_arr="101104105106109111112113114116117120122123124" fairly big string If i want to split three numbers from them like 101,104,105 and store them in $array .What should i do? I tried doing this: preg_match_all('/[0-9]{3}$/',"$text_arr",$array); 回答1: The easiest way to do this is with preg_split()Docs: $result = preg_split('/(\d{3})/', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); See it working, or the result: Array ( [0] => 101 [1] => 104 [2] => 105 [3] =>