简体   繁体   中英

PHP: how to split a string with a delimiter

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM