Frage

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,

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top