Hello again to all..
I have trouble of modifying this code.. A person gave me the link on where can i find answers to my problem on PHP String Parsing.. However it took me the whole weekend to modify the code.. I really have no idea on how to get the results that i want.. Could someone help me?
This is the code
<?php
function parse_csv($file,$number,$comma=',',$quote='"',$newline="\n") {
$db_quote = $quote . $quote;
$file = trim($file);
$file = str_replace("\r\n",$newline,$file);
$file = str_replace($db_quote,'"',$file);
$file = str_replace('#1#','',$file);
$file = str_replace($number,'',$file);
$file = str_replace($s++,'',$file);
$file = str_replace(',",',',,',$file);
$file .= $comma;
$inquotes = false;
$start_point = 0;
$row = 0;
for($i=0; $i<strlen($file); $i++) {
$char = $file[$i];
if ($char == $quote) {
if ($inquotes) {
$inquotes = false;
}
else {
$inquotes = true;
}
}
if (($char == $comma or $char == $newline) and !$inquotes) {
$cell = substr($file,$start_point,$i-$start_point);
$cell = str_replace($quote,'',$cell);
$cell = str_replace('"',$quote,$cell);
$data[$row][] = $cell;
$start_point = $i + 1;
if ($char == $newline) {
$row ++;
}
}
}
return $data;
}
$file ='#1# "4","+447980123456","+447781484145","","2009-06-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange"';
$array = parse_csv($file,"+447980123456");
print_r($array);
?>
This is the result of that code
Array ( [0] => Array ( [0] => 4 [1] => [2] => +447781484145 [3] => [4] => 2009-06-08 [5] => 10:38:15 [6] => hello "," world [7] => Orange 5 [8] => [9] => +447781484146 [10] => [11] => 2009-07-08 [12] => 10:38:55 [13] => hello world [14] => Orange ) )
What i would like as the result is a string that shows this information..
Originator : +447781484145, Date : 2009-07-07, Time : 10:38:15, Message : hello world
Originator : +447781484146, Date : 2009-07-08, Time : 10:38:55, Message : hello world
Any help will be appreciated..
thanks in advance..