문제

I have this string that I would like to split.I want it to split the string starting with 1060 and retain the string but when I use preg_split(), it removes the string.

my code is this:

$array = preg_split("/1060[\s]*/",$str);

if there is any other method or function i can use, i will be very grateful.

Regards,

도움이 되었습니까?

해결책

Positive lookaheads:

$array = preg_split("/(?=1060\s)/",$str);

(?=1060\s) is a positive lookahead - it asserts that the regex inside it (1060\s) can be matched, but doesn't match it. Therefore, this will match an empty string right before the match and split the text correctly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top