Jump to content

[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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.