我试图在php中爆炸一行文本。这样,一条线由
组成
" [名称]"" [状态]"" [性别]"" [DATE_OF_BIRTH]"&# 34; [年龄]"" [testing_date]",的" [answer_for_Test_V_nos._1_to_168]" 下," [SAI_Raw_Score] "" [RPM_Raw_Score]"" [English_Raw_Score]"" [Math_Test_I_Raw_Score]"" [Math_Test_II_Raw_Score]&# 34;," [Total_Score]"
粗体(总共169个数据)是我试图存储在数组中的那个。
以下是示例行:
"DELACRUZ JUAN H","F","M","101887","18","030105","3","0","1","2","3","3","0","2","1","0","2","1","1","3","3","3","1","2","3","3","2","1","1","2","1","2","1","3","1","0","1","3","0","2","1","0","1","3","1","1","1","1","0","2","1","1","1","2","0","3","0","3","3","1","0","2","3","3","0","2","0","2","0","0","1","2","3","3","1","2","1","3","2","2","0","3","2","2","1","1","0","0","2","3","2","0","0","2","3","3","0","1","0","3","0","1","1","3","2","0","3","1","1","0","1","2","1","0","1","3","2","0","3","0","2","2","2","2","1","1","0","3","3","3","2","3","2","1","2","3","2","1","2","0","0","1","1","2","0","0","2","3","1","2","2","3","3","1","0","0","0","0","3","2","2","1","1","3","1","1","0","2","0","2","2","1","3","2","060","055","083","015","042","0255"
这是爆炸的代码,但这里的数组不起作用:
list($name, $status, $gender, $bday, $age, $date, $answers[169], $SAI, $RPM, $english, $math1, $math2, $total) = explode(",", $line);
请帮助,如何使用" list()= explode()"?将这169个值分解为数组的每个索引?或者除了使用list()= explode()之外还有其他方法吗?
答案 0 :(得分:1)
只需使用array_splice提取您需要的值。
$line = '"DELACRUZ JUAN H","F","M","101887","18","030105","3","0","1","2","3","3","0","2","1","0","2","1","1","3","3","3","1","2","3","3","2","1","1","2","1","2","1","3","1","0","1","3","0","2","1","0","1","3","1","1","1","1","0","2","1","1","1","2","0","3","0","3","3","1","0","2","3","3","0","2","0","2","0","0","1","2","3","3","1","2","1","3","2","2","0","3","2","2","1","1","0","0","2","3","2","0","0","2","3","3","0","1","0","3","0","1","1","3","2","0","3","1","1","0","1","2","1","0","1","3","2","0","3","0","2","2","2","2","1","1","0","3","3","3","2","3","2","1","2","3","2","1","2","0","0","1","1","2","0","0","2","3","1","2","2","3","3","1","0","0","0","0","3","2","2","1","1","3","1","1","0","2","0","2","2","1","3","2","060","055","083","015","042","0255"';
$splitArray = explode(",", $line);
$testAnswers = array_splice($splitArray, 6, 168); //Extract the values that you need. Leave the rest as they are.
list($name, $status, $gender, $bday, $age, $date, $SAI, $RPM, $english, $math1, $math2, $total) = $splitArray; //Put the remaining into the variables as required
var_dump($testAnswers); //All the answers
var_dump($name); //The name