开发者

explode() in PHP

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 ", "

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜