Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP split alternative?

Tags:

php

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

like image 481
igorgue Avatar asked May 11 '10 18:05

igorgue


People also ask

Is split () deprecated?

split() is deprecated as of PHP 5.3. 0. preg_split() is the suggested alternative to this function. 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.

What is difference between split and explode in PHP?

Both the functions are used to Split a string. However, Split is used to split a string using a regular expression. On the other hand, Explode is used to split a string using another string.

How do you split in PHP?

explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.

What is split function in PHP?

PHP - Function split() The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.


2 Answers

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

like image 183
Sarfraz Avatar answered Oct 12 '22 04:10

Sarfraz


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.

like image 33
salathe Avatar answered Oct 12 '22 04:10

salathe