好吧,让我们只是为了好玩
$string = "here is a sample: this text, and this will be exploded. this also | this one too :)";
$needle = array(",",".","|",":");
$chars = implode($needle);
$list = array();
while (false !== $match = strpbrk($string, $chars)) {
$list[] = $match[0];
$string = substr($match, 1);
}
var_dump($list);
你可以看到它工作- 阅读strpbrk
解释
strpbrk
返回第一个匹配字符之后的字符串
转弯 1
$string = "here is a sample: this text, and this will be exploded. this also | this one too :)";
// strpbrk matches ":"
$match = ": this text, and this will be exploded. this also | this one too :)";
// Then, we push the first character to the list ":"
$list = array(':');
// Then we substract the first character from the string
$string = " this text, and this will be exploded. this also | this one too :)";
转 2
$string = " this text, and this will be exploded. this also | this one too :)";
// strpbrk matches ","
$match = ", and this will be exploded. this also | this one too :)";
// Then, we push the first character to the list ","
$list = array(':', ',');
// Then we substract the first character from the string
$string = " and this will be exploded. this also | this one too :)";
以此类推,直到没有匹配
转 5
$string = ")";
// strpbrk doesn't match and return false
$match = false;
// We get out of the while