function pData::importFromCSV in Visitors 7.2
Same name and namespace in other branches
- 8 pchart/pData.inc \pData::ImportFromCSV()
- 7 pChart/class/pData.class.php \pData::importFromCSV()
- 7.0 pchart/pData.inc \pData::ImportFromCSV()
File
- pChart/
class/ pData.class.php, line 667
Class
Code
function importFromCSV($FileName, $Options = "") {
$Delimiter = isset($Options["Delimiter"]) ? $Options["Delimiter"] : ",";
$GotHeader = isset($Options["GotHeader"]) ? $Options["GotHeader"] : FALSE;
$SkipColumns = isset($Options["SkipColumns"]) ? $Options["SkipColumns"] : array(
-1,
);
$DefaultSerieName = isset($Options["DefaultSerieName"]) ? $Options["DefaultSerieName"] : "Serie";
$Handle = @fopen($FileName, "r");
if ($Handle) {
$HeaderParsed = FALSE;
$SerieNames = "";
while (!feof($Handle)) {
$Buffer = fgets($Handle, 4096);
$Buffer = str_replace(chr(10), "", $Buffer);
$Buffer = str_replace(chr(13), "", $Buffer);
$Values = preg_split("/" . $Delimiter . "/", $Buffer);
if ($Buffer != "") {
if ($GotHeader && !$HeaderParsed) {
foreach ($Values as $Key => $Name) {
if (!in_array($Key, $SkipColumns)) {
$SerieNames[$Key] = $Name;
}
}
$HeaderParsed = TRUE;
}
else {
if ($SerieNames == "") {
foreach ($Values as $Key => $Name) {
if (!in_array($Key, $SkipColumns)) {
$SerieNames[$Key] = $DefaultSerieName . $Key;
}
}
}
foreach ($Values as $Key => $Value) {
if (!in_array($Key, $SkipColumns)) {
$this
->addPoints($Value, $SerieNames[$Key]);
}
}
}
}
}
fclose($Handle);
}
}