举个例子,在一个网站的电影数据表里有个字段是演员,一部电影里有多个演员,现在需要把每个演员分别显示出来,用程序来实现就是把这个演员字段里的字符串里的每个演员放到同一个数组里。演员可能是这样录入的 徐铮,王宝强,刘德华 也可能是这样录入的 徐铮|王宝强|刘德华 或者 是 徐铮;王宝强;刘德华
if(strstr($players,"|")){ //如果这个字符串里包含|
$playerarr=(explode("|",$players));//把关键词用空格切割为数组元素
}elseif(strstr($players,";")){ //如果这个字符串里包含中文的分号
$playerarr=(explode(";",$players));//把关键词用空格切割为数组元素
}elseif(strstr($players,";")){ //如果这个字符串里包含英文的分号
$playerarr=(explode(";",$players));//把关键词用空格切割为数组元素
}elseif(strstr($players,",")){ //如果这个字符串里包含中文的逗号
$playerarr=(explode(",",$players));//中文逗号
}elseif(strstr($players,",")){ //如果这个字符串里包含英文的逗号
$playerarr=(explode(",",$players));//英文逗号
}elseif(strstr($players,PHP_EOL)){ /
$playerarr=(explode(PHP_EOL,$players));//把关键词用空格切割为数组元素
}else{
$playerarr[]=$players;
echo $playerarr[0];
}
·关于我们·免责声明·服务条款·RSS订阅·dede168.com技术支持
Copyright © 1998-2015 All rights reserved.