tags:

views:

874

answers:

5

PHP is telling me that split is deprecated, what's the alternative method I should use?

+12  A: 

explode is the alternative. However, if you meant to split through a regular expression, the alternative is preg_split instead.

Sarfraz
KA-BOOOOOM!!!!! :)
FrustratedWithFormsDesigner
As a pythonista I loled at that :)
igorgue
I disagree - `explode` is not the alternative, since it does not perform the same function as `split`, that is: to split a string *by a regular expression*. For that purpose, use `preg_split`.
nickf
@nickf: That's rightly pointed, i should have added that initially on. Thanks
Sarfraz
+3  A: 

Str_split or preg_split if you need to split by regular expressions. Explode if you need to split by something simple.

Also for the future, if you ever want to know what PHP wants you to use if something is depreciated you can always check out the function in the manual and it will tell you alternatives.

evolve
+8  A: 

split is deprecated since it is part of the family of functions which make use of POSIX regular expressions; that entire family is deprecated in favour of the PCRE (preg_*) functions.

If you do not need the regular expression functionality, then explode is a very good choice (and would have been recommended over split even if that were not deprecated), if on the other hand you do need to use regular expressions then the PCRE alternate is simply preg_split.

salathe
+1  A: 

You can use easier preg_match instead...better and faster all of those ones...

$var = "Get this var" preg_match("/(.*)<\/tag>/", $var , $new_var); echo $new_var['1']; => Get this var

Andre Cotelo
+1  A: 

Yes, I would use explode or you could use:

preg_split

Which is the advised method with PHP 6. preg_split Documentation

Nitroware