This kind of regex parsing leads poor performance. So that, it was deprecated and removed from PHP. The following code shows an example for the split function with [ — : ] pattern to split the given string.
But as of 5. So, if we use this function in later versions of PHP greater than 5. There are some alternate functions in PHP for splitting a string into an array. These are listed as follows. The explode is an alias of split function and uses string instead of regex pattern for splitting.
Sarfraz Sarfraz k 70 70 gold badges silver badges bronze badges. 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.
Thanks — Sarfraz. In various languages, the split method does not always accept regular expressions. NET, Python, the String. Thus, explode is correct. It's compatible with Visual Basic. NET's String. Nice — Md Ashraful Islam. Amal Murali Community Bot 1 1 1 silver badge. Gigala 2 2 silver badges 10 10 bronze badges. Andre Cotelo Andre Cotelo 21 1 1 bronze badge.
Addo Solutions Addo Solutions 1, 3 3 gold badges 18 18 silver badges 36 36 bronze badges. Alexandrw Alexandrw 1, 2 2 gold badges 7 7 silver badges 10 10 bronze badges. Ferdinand Ferdinand 21 2 2 bronze badges. Sign up or log in Sign up using Google. Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the case-sensitive regular expression pattern.
For example, if there is no occurrence of pattern , an array with only one element will be returned. Of course, this is also true if string is empty. If an error occurs, split returns false. Example 1 split example. Example 2 split example. 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.
Submit a Pull Request Report a Bug. Parametri pattern Case sensitive regular expression. Example 2 split example To parse a date which may be delimited with slashes, dots, or hyphens:. Note Sfat split is deprecated as of PHP 5. It seemed to split on a comma even though it was between a pair of quotes. It's evident but not mentioned in the documentation that using asterisks is more restricted than in a normal regular expression. A period is a regular expression pattern for a single character.
0コメント