Home  >  Article  >  Backend Development  >  explode函数分割,求助

explode函数分割,求助

WBOY
WBOYOriginal
2016-06-23 14:02:04960browse

$str = "爸爸,妈妈,奶奶;爷爷.外公,外伯,舅舅";
$net = explode(',',$str);

如何将分害成
1=>爸爸
2=>妈妈
3=>奶奶
4=>爷爷
5=>外公
6=>外伯
7=>舅舅


回复讨论(解决方案)

$str = "爸爸,妈妈,奶奶;爷爷.外公,外伯,舅舅";$str = str_replace(';', ',', $str);$str = str_replace('.', ',', $str);$net = explode(',',$str);var_dump($net);

$net = preg_split('/[,;.]/',$str);print_r($net);

Array
(
    [0] => 爸爸
    [1] => 妈妈
    [2] => 奶奶
    [3] => 爷爷
    [4] => 外公
    [5] => 外伯
    [6] => 舅舅
)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn