I have used the explode function in PHP to break up a string into an array giving "," as the s开发者_如何学Ceparator to break the string. My question is, what if the string does not contain the "," separator "," ? will there be an error or will the string be treated as an array with a single element?
While it would be very easy to test, I'll just show the output.
php -r 'print_r(explode(",", "this is a test"));'
Array
(
[0] => this is a test
)
From PHP docs:
If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned
You could also use regex split if they use delimiters such as ; and ", "
精彩评论