如何在PHP

时间:2018-05-28 05:15:49

标签: php csv

我试图将CSV分成两个字符串LHS_String和RHS_String。例如,我有以下CSV -

customer^id,record^id
customer^fname,record^first_name
cusomer^gender,record^gender

输出应该像 -

LHS_String : customer^id
RHS_String : record^id

1 个答案:

答案 0 :(得分:0)

简短回答,阅读http://php.net/manual/en/function.explode.php

示例:

<?php
$data  = "customer^id,record^id\r\n";
$data .= "customer^fname,record^first_name\r\n";
$data .= "cusomer^gender,record^gender\r\n";

$p1 = explode("\r\n", $data);
$p2 = array();
foreach($p1 as $key => $line){
  $p2[$key] = explode(",", $line);
}

echo "LHS_String : " . $p2[0][0] . "\r\n";
echo "RHS_String : " . $p2[0][1] . "\r\n";
?>