使用PHP解析SOAP'CSV'生成的数组返回结果

时间:2013-01-31 22:09:36

标签: php sql arrays

我正在使用这个php来解析数据并迭代行但是逗号和双引号的配置让我非常困惑。

非常感谢任何帮助。

我正在使用的这段代码打破了包含逗号的字符串。

$getDataExploded = array();
$out = "";
foreach($getData as $getDataRows)
{
    $getDataExploded = explode(",",$getDataRows);
        $out .= '<div id="'.$getDataExploded[4].'" class="row"><span style="font-size:14px; color:#646464;">'.$getDataExploded[0].'</span><br><span style="font-size:12px; color:#3877D9;">'.$getDataExploded[1].' / '.$getDataExploded[2].'<br><em style="font-size:11px; color:#757575;">Posted: '.$getDataExploded[3].'</em></span></div>';


}

echo($out);

以下是我尝试解析的数组看起来像......

array(29){[0] =&gt; string(62)“'wefwefwef','ewfwefwefwef','wefwefwef',1/29/2013 9:09:04 PM,37”[1] =&gt; string(47)“'wefwef','wefwefwef','',1/29/2013 9:08:11 PM,36”[2] =&gt; string(82)“'You Like You Never Knew','Sandy Hurricanes','Boise Idaho',1/29/2013 9:06:12 PM,35”[3] =&gt; string(32)“'','','',1/29/2013 9:04:10 PM,34”[4] =&gt; string(49)“'wefwefwef','wfwefwef','',1/29/2013 9:02:05 PM,33”[5] =&gt; string(82)“'Sheriff Recruitment','Sheriff Recruitment','Rhode Island',1/28/2013 7:13:53 PM,25”[6] =&gt; string(81)“'邻居销售代表','Trugreen','Warwick',1 / 28/2013 7:13:53 PM,24”[7] =&gt; string(86)“'警察招募','克兰斯顿市','克兰斯顿',2013年1月28日下午7:13:53,23”[8] =&gt; string(144)“'RNs,LPNs,CNAs,护士从业者和医师助理招募','Adil Business Systems,Inc。','Rhode Island',1/28/2013 7:13:53 PM,22”[9 ] =&GT; string(79)“'Econotel EBS','Telecommunications Installer','Rumford',1/28/2013 7:13:53 PM,21”[10] =&gt; string(73)“'Full-Charge Bookkeeper','Econotel EBS','Rumford',1/28/2013 7:13:53 PM,20”[11] =&gt; string(127)“'Certified Nursing Assistants','Morning Star Home Care','Wakefield,Westerly,Newport and Narragansett',1/28/2013 7:13:53 PM,19”[12] =&gt;字符串(78)“'汽车会计','殖民地丰田','史密斯菲尔德',1/28/2013 7:13:53 PM,18”[13] =&gt; string(89)“'Certified Nursing Assistants','All About Home Care','Middletown',1 / 28/2013 7:13:53 PM,17”[14] =&gt; string(97)“'Customer Development / Inside Sales','Hexagon Metrology','North Kingstown',1/28/2013 7:13:53 PM,16”[15] =&gt; string(85)“'RI警长','RI公共安全部','全州',1/28/2013 7:13:53 PM,15”[16] =&gt; string(89)“'Certified Nursing Assistants','Morning Star Home Care','Warwick',1/28/2013 7:13:53 PM,14”[17] =&gt; string(95)“'入门级软件开发人员','Hexagon Metrology','North Kingstown',1/28/2013 7:13:53 PM,13”[18] =&gt; string(83)“'电子技师','Purvis Systems公司','Middletown',1/28/2013 7:13:53 PM,12”[19] =&gt; string(81)“'Nurse Practitioner','Memorial Hospital','Plainville,MA',1/28/2013 7:13:53 PM,11”[20] =&gt; string(86)“'Home Care Physical Therapist','Memorial Hospital','Pawtucket',1/28/2013 7:13:53 PM,10”[21] =&gt; string(87)“'Real Estate Specialist','Linear Title and Closing','Middletown',1/28/2013 7:13:53 PM,9”[22] =&gt; string(77)“'Equipment Technician','Angelica Textiles','Pawtucket',1/28/2013 7:13:53 PM,8”[23] =&gt; string(68)“'Painting Crew Leader','LOPCO','Rhode Island',1/28/2013 7:13:53 PM,7”[24] =&gt; string(102)“'Diesel Mechanic','Interstate Diesel Equipment Service,Inc。','North Kingstown',1 / 28/2013 7:13:53 PM,6”[25] =&gt; string(73)“'Hydromat Machine Operators','Greystone','Lincoln',1/28/2013 7:13:53 PM,5”[26] =&gt; string(85)“'全国销售经理','Hexagon Metrology','North Kingstown',1/28/2013 7:13:53 PM,4”[27] =&gt; string(131)“'North Providence Probationary Police Officer Recruitment','North Providence','North Providence',1 / 28/2013 7:13:53 PM,3”[28] =&gt; string(113)“'Territory Service Representatives','Scotts Lawn Service','Rhode Island and Massachusetts',1/28/2013 7:13:53 PM,2”}

1 个答案:

答案 0 :(得分:1)

PHP提供了一种str_getcsv()方法,您可能会发现它很有用。它阻止你需要担心逗号和文本分隔符。

$getDataExploded = array();
$out = "";
foreach($getData as $getDataRows)
{
    $getDataExploded = str_getcsv($getDataRows);
    //Do out stuff here `htmlentities` as required

}

echo($out);

编辑:如jeroen所指出的改变了对htmlentities的使用