PHP explode(), delimiter being returned? [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
开发者_如何学C Improve this questionI'm not sure why but the explode function doesn't seem to be working for me.
I have a string which contains one or more sets of comma-seperated values. These sets are delimied by starting / ending square brackets.
After stripping off the ending "[" and "]", I thought it would be simple to then use the explode function to get the results seperated by "][". Instead, I get something weird.
$rawInserts = '[1,2,3,4,5][2,3,4,5,6][3,4,5,6,7]';
$the_inserts = substr($rawInserts,1,strlen($rawInserts)-2);
echo "$the_inserts \n"; //returns "1,2,3,4,5][2,3,4,5,6][3,4,5,6,7"
$inserts = explode($the_inserts , "][");
echo print_r($inserts)."\n"; // returns one item array containing "][";
why is it returning "]["? (FYI, I tried this exact example and it fails).
Thanks in advance.
array explode ( string $delimiter , string $string [, int $limit ] )
Delimiter first, string second.
Switch the parameters. It's delimiter first and string as second parameter:
$inserts = explode('][', $the_inserts);
it should be $inserts = explode("][",$the_inserts );
I myself cannot remember the parameters for every function, so just go to the php.net website and search for the explode function.
精彩评论