PHP Split Problem
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
split
is deprecated. You should use explode
$arr = explode('^', "ItemOne^ItemTwo^Item.Three^");
Try
explode("^", "ItemOne^ItemTwo^Item.Three^");
since your search pattern isn't a regex.
Are you sure you're not just looking for explode
?
explode('^', 'ItemOne^ItemTwo^Item.Three^');
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.
精彩评论