Jump to content

Archived

This topic is now archived and is closed to further replies.

dlf1987

[SOLVED] Deprecated: Function split() is deprecated

Recommended Posts

right now im using

 

$cart2 = "100~Product1~2500~2,200~Product2~2900~1";

comma is the seperator

 

$arr = explode(",", $cart2);
reset($arr);

foreach($arr as $line){
list($A, $B, $C, $D) = split('~', $line);
echo $A;
echo "<br>";
} 

 

the above seems to work fine.. but its giving me this error

 

"Deprecated: Function split() is deprecated"

 

Apparently "split" is removed as of PHP 6.0.0 according to php.net

 

instead of hiding the error i would like to know if theres a better way to write the code for what im trying to do?

 

Thanks

Share this post


Link to post
Share on other sites
preg_split(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to split(). If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine.

 

However, for what you are doing, just use explode() again.

Share this post


Link to post
Share on other sites

I'm not familiar with the split function, but at a quick glance at the reference it seems a regex version of explode. Since in your code you don't appear to be using any regex you shold probably just use explode, it will likely be quicker. If you do require regular expressions then how about the preg_split function.

 

Edit: D'oh.

Share this post


Link to post
Share on other sites

$arr = explode(",", $cart2);

reset($arr);

 

foreach($arr as $line){

  list($A, $B, $C, $D) = split('~', $line);

both are the same thing... replace split with explode

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.