简体   繁体   English

PHP中的多个分隔符拆分字符串

[英]Split String by Multiple Delimiters in PHP

Can strings be parsed into an array based on multiple delimiters? 可以根据多个分隔符将字符串解析为数组吗? as explained in the code: 如代码中所述:

$str ="a,b c,d;e f";
//What i want is to convert this string into array
//using the delimiters space, comma, semicolon

PHP PHP

$str = "a,b c,d;e f";

$pieces = preg_split('/[, ;]/', $str);

var_dump($pieces);

CodePad . CodePad

Output 产量

array(6) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  string(1) "d"
  [4]=>
  string(1) "e"
  [5]=>
  string(1) "f"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM