There is a string like a/b/c/d/e .

It is necessary to push it into an array in this way:

 $a=explode('/', 'a/b/c/d/e'); 

The separator can be any.

How to make it so that if the separator is \ , then the separator is not counted?

Those. if there is a shielding character, then this option does not work \/ .

    1 answer 1

    This is where preg_split () is more suitable than explode ().

     $str = 'a/b/c/d/e\/f/g/h\/i'; $arr = preg_split('~(?<!\\\)/~',$str); 

    As a result, we get:

     Array ( [0] => a [1] => b [2] => c [3] => d [4] => e\/f [5] => g [6] => h\/i ) 
    • What ?<! it mean ?<! ? - fjghkjg
    • @fjghkjg, Negative viewing back with denial. / (? <! a) b / - finds "b" if there is no "a" in front of it - Deonis
    • But how can you write this expression differently for example? /[^\\\]\// or am I mistaken? - fjghkjg
    • @fjghkjg, you can check it yourself)) Wrong. - Deonis
    • @Deonis, not strong in regular expressions) Did I understand correctly that without ?<! not enough? - fjghkjg