views:

25

answers:

4

Hello,

I am trying to use (and I've tried both) preg_split() and split() and neither of these have worked for me. Here are the attempts and outputs.

preg_split("^", "ItemOne^ItemTwo^Item.Three^");
//output - null or false when attempting to implode() it.
preg_split("\^", "ItemOne^ItemTwo^Item.Three^");
//output - null or false when attempting to implode() it. Attempted to escape the needle.
//SAME THING WITH split().

Thanks for your help... Christian Stewart

+1  A: 

split is deprecated. You should use explode

$arr = explode('^', "ItemOne^ItemTwo^Item.Three^");

Zurahn
Thanks, this worked.
Christian Stewart
+1  A: 

Try

explode("^", "ItemOne^ItemTwo^Item.Three^");

since your search pattern isn't a regex.

LesterDove
+1  A: 

Are you sure you're not just looking for explode?

explode('^', 'ItemOne^ItemTwo^Item.Three^');

Josh Leitzel
A: 

Since you are using preg_split you are trying to split the string by a given regular expresion. The circumflex (^) is a regular expression metacharacter and therefore not working in your example.

btw: preg_split is an alternative to split and not deprecated.

Nick