phpsplitpreg-split

How to replace split() with preg_split() in my PHP code?


Could you please help me with converting $x_ary = split('&x=', $url); to the preg_split() equivalent?


Solution

  • In most cases you just need to add delimiters:

     preg_split('/&x=/',$url)
    

    / are fine if you do not need them as part of the pattern. And none of the other symbols are meta characters, so don't need escaping.

    Take note that in your case you could just use explode instead, since you don't need a regex.