Based on the previous question
How to correctly replace explode in my case?
How to make a variant with // ?
It works incorrectly:
$str = 'a/b/c/d/e//f/g/h//i'; $arr = preg_split('~(?<!/)/~',$str); The answer should be such
a b c d e//f g h//i A little thought, I wrote this code:
$str = 'a/b/c/d/e//f/g/h//i'; $arr = preg_split('/(?<!\/)\/(?!\/)/',$str); Answer:
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e//f [5] => g [6] => h//i ) At first glance, it works correctly, but if there are a lot of //// symbols, then there are no:
$str = 'a/b/c/d/e////f/g/h//i'; $arr = preg_split('/(?<!\/)\/(?!\/)/',$str); The answer should be:
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => // [6] => f [7] => g [8] => h//i ) How to fix? @Deonis