質問

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