dlf1987 Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176877-solved-deprecated-function-split-is-deprecated/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2009 Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176877-solved-deprecated-function-split-is-deprecated/#findComment-932622 Share on other sites More sharing options...
cags Posted October 7, 2009 Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176877-solved-deprecated-function-split-is-deprecated/#findComment-932625 Share on other sites More sharing options...
Zane Posted October 7, 2009 Share Posted October 7, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/176877-solved-deprecated-function-split-is-deprecated/#findComment-932627 Share on other sites More sharing options...
dlf1987 Posted October 7, 2009 Author Share Posted October 7, 2009 thanks guys.. didn't even think to use it explode twice Quote Link to comment https://forums.phpfreaks.com/topic/176877-solved-deprecated-function-split-is-deprecated/#findComment-932632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.