如何将分号分隔的字符串拆分为字符串中的单独项?

时间:2016-12-07 05:00:14

标签: php

我需要将我的字符串输入拆分为分号,如下所示。

.frame {
  overflow-x: scroll;
  width: 500px; /* this can be any width */
  border: 3px solid deeppink;
}

/* 
  pane width = item count * (item width + horizontal margins)
*/
.pane {
  width: 1020px; /* 102 * 10 */
}

.item {
  display: block;
  float: left;
  width: 100px; /* calculated width is 102px b/c of margin-right */
  margin: 0 2px 2px 0;
  height: 50px;
  background-color: grey;
}

我需要拆分

Original String: Loganathan <logu@gmail.com>; Nathan <nathan@gmail.com>; Tester <tester@gmail.com>; 

我怎样才能完成这项工作?

2 个答案:

答案 0 :(得分:1)

您可以使用 [ { "0":"5.0", "feedback":"5.0", "1":"5", "COUNT(fc.trainee_id)":"5", "2":"1", "sessions":"1", "3":"UET_Q4_18_EBK_FINFUNC_2017", "training_id":"UET_Q4_18_EBK_FINFUNC_2017", "4":"Giridhar Mohan Bhat", "NAME":"Giridhar Mohan Bhat", "5":null, "signoff_rating":null }, { "0":"4.4", "feedback":"4.4", "1":"5", "COUNT(fc.trainee_id)":"5", "2":"1", "sessions":"1", "3":"UET_Q3_10_HNB_FINTECH_2016", "training_id":"UET_Q3_10_HNB_FINTECH_2016", "4":"Geetha Kondapalli", "NAME":"Geetha Kondapalli", "5":null, "signoff_rating":null }, { "0":"4.7", "feedback":"4.7", "1":"10", "COUNT(fc.trainee_id)":"10", "2":"1", "sessions":"1", "3":"UET_Q3_5_SIB_FINTECH_2016", "training_id":"UET_Q3_5_SIB_FINTECH_2016", "4":"Geetha Kondapalli", "NAME":"Geetha Kondapalli", "5":"7", "signoff_rating":"7" }, { "0":"3.9", "feedback":"3.9", "1":"10", "COUNT(fc.trainee_id)":"10", "2":"1", "sessions":"1", "3":"UET_Q3_5_SIB_FINTECH_2016", "training_id":"UET_Q3_5_SIB_FINTECH_2016", "4":"Abhishek", "NAME":"Abhishek", "5":"7", "signoff_rating":"7" }, { "0":"4.0", "feedback":"4.0", "1":"5", "COUNT(fc.trainee_id)":"5", "2":"1", "sessions":"1", "3":"UET_Q3_11_HNB_FINTECH_2016", "training_id":"UET_Q3_11_HNB_FINTECH_2016", "4":"Jason Bangaram", "NAME":"Jason Bangaram", "5":null, "signoff_rating":null }, { "0":"4.8", "feedback":"4.8", "1":"20", "COUNT(fc.trainee_id)":"20", "2":"2", "sessions":"2", "3":"UET_Q3_5_SIB_FINTECH_2016", "training_id":"UET_Q3_5_SIB_FINTECH_2016", "4":"Jason Bangaram", "NAME":"Jason Bangaram", "5":"7", "signoff_rating":"7" } ] 功能。 explode link

explode

为您提供类似

的输出
$str = "Loganathan <logu@gmail.com>; Nathan <nathan@gmail.com>; Tester <tester@gmail.com>;";
$str = str_replace(array(" <",">"),array(", ",""),$str);
$converted = explode(";",$str);
print_r($converted);

答案 1 :(得分:1)

使用explode

$str = 'Loganathan <logu@gmail.com>; Nathan <nathan@gmail.com>; Tester <tester@gmail.com>;';
//Removing the "<>" symbols
$str = str_replace("<",",",$str);
$str = str_replace(">","",$str);    
$result = explode(";", $str);    

print_r(array_filter($result)); //Removing empty array values

<强>结果:

Array
(
    [0] => Loganathan ,logu@gmail.com
    [1] =>  Nathan ,nathan@gmail.com
    [2] =>  Tester ,tester@gmail.com        
)