Home > Php si Mysql > php explode by multiple delimiters

php explode by multiple delimiters

You need to explode a string by multiple delimiters?

You need to use  the preg_split function. Preg_split is a function  similar to explode.

Explode splits a string by a string, Preg_split splits a string  by a regular expression.


You have a text and you need to explode it by  two strings,  “with” and “and”.

$string = "One with two and three";

$array = preg_split("( with | and )", $string);



Array (     [0] = One     [1] = two     [2] = three  )

Php si Mysql ,

  1. May 2nd, 2011 at 23:18 | #1

    Wow, that’s a really clever way of tinhikng about it!

  1. No trackbacks yet.