开发者

PHP explode(), delimiter being returned? [closed]

开发者 https://www.devze.com 2023-04-10 06:11 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

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 question

I'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.

0

精彩评论

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

关注公众号