当前位置: 首页>>代码示例>>PHP>>正文


PHP csvToArray函数代码示例

本文整理汇总了PHP中csvToArray函数的典型用法代码示例。如果您正苦于以下问题:PHP csvToArray函数的具体用法?PHP csvToArray怎么用?PHP csvToArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了csvToArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: csvToJson

function csvToJson($feed)
{
    // Arrays we'll use later
    $keys = array();
    $newArray = array();
    // Do it
    $data = csvToArray($feed, ',');
    // Set number of elements (minus 1 because we shift off the first row)
    $count = count($data) - 1;
    //Use first row for names
    $labels = array_shift($data);
    foreach ($labels as $label) {
        $keys[] = $label;
    }
    // Add Ids, just in case we want them later
    $keys[] = 'id';
    for ($i = 0; $i < $count; $i++) {
        $data[$i][] = $i;
    }
    // Bring it all together
    for ($j = 0; $j < $count; $j++) {
        $d = array_combine($keys, $data[$j]);
        $newArray[$j] = $d;
    }
    // Print it out as JSON
    return json_encode($newArray);
}
开发者ID:royopa,项目名称:sigcm-angular,代码行数:27,代码来源:csv-to-json.php

示例2: __construct

	public function __construct () {
		global $config;

		$this->setDB = new SetDB();
		$this->artDB = new ArtDB($this->setDB);
		$this->cardDB = new CardDB($this->setDB, $this->artDB);
		$this->formatDB = new FormatDB($this->setDB, $this->cardDB);
		$this->fontSizeDB = new FontSizeDB($config['card.text.use.font.size.cache']);
		$this->titleToLandColors = csvToArray('data/titleToLandColors.csv');
		$this->convertor = new Convertor();
	}
开发者ID:GarikRC,项目名称:arcane,代码行数:11,代码来源:ImageWriter.php

示例3: spreadsheet_json

 /**
  * @param $url
  */
 public function spreadsheet_json($url)
 {
     //        header('Content-type: application/json');
     // Set your CSV feed
     $feed = $url;
     // Arrays we'll use later
     $keys = array();
     $newArray = array();
     // Function to convert CSV into associative array
     function csvToArray($file, $delimiter)
     {
         if (($handle = fopen($file, 'r')) !== FALSE) {
             $i = 0;
             while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
                 for ($j = 0; $j < count($lineArray); $j++) {
                     $arr[$i][$j] = $lineArray[$j];
                 }
                 $i++;
             }
             fclose($handle);
         }
         return $arr;
     }
     // Do it
     $data = csvToArray($feed, ',');
     // Set number of elements (minus 1 because we shift off the first row)
     $count = count($data) - 1;
     //Use first row for names
     $labels = array_shift($data);
     foreach ($labels as $label) {
         $keys[] = $label;
     }
     // Add Ids, just in case we want them later
     $keys[] = 'id';
     for ($i = 0; $i < $count; $i++) {
         $data[$i][] = $i;
     }
     // Bring it all together
     for ($j = 0; $j < $count; $j++) {
         $d = array_combine($keys, $data[$j]);
         $newArray[$j] = $d;
     }
     // Print it out as JSON
     return json_encode($newArray, JSON_PRETTY_PRINT);
 }
开发者ID:frankinedinburgh,项目名称:codeigniter_sandbox,代码行数:48,代码来源:Data_model.php

示例4: generate_json

function generate_json($doc)
{
    $keys = array();
    $geoData = array();
    $data = csvToArray($doc, ',');
    // Set number of elements (minus 1 because we shift off the first row)
    $count = count($data) - 1;
    //Use first row for names
    $labels = array_shift($data);
    foreach ($labels as $label) {
        $keys[] = $label;
    }
    // Bring it all together
    for ($j = 0; $j < $count; $j++) {
        $d = array_combine($keys, $data[$j]);
        $geoData[$j] = $d;
    }
    return $geoData;
}
开发者ID:AmericanNumismaticSociety,项目名称:migration_scripts,代码行数:19,代码来源:bm-concordances.php

示例5: __construct

	function __construct() {
		$this->mtgoIdToTitle = csvToArray('data/mtgoIdToTitle.csv');
	}
开发者ID:GarikRC,项目名称:arcane,代码行数:3,代码来源:Convertor.php

示例6: header

<?php

header('Content-type: text/csv');
ini_set("auto_detect_line_endings", true);
$FN_FILE = './data/CSV_Database_of_First_Names.csv';
$LN_FILE = './data/CSV_Database_of_Last_Names.csv';
$NUM_RECORDS = checkSet('recordcount', 100, false);
$FN_Array = csvToArray($FN_FILE);
$FN_Array_Sz = count($FN_Array);
$LN_Array = csvToArray($LN_FILE);
$LN_Array_Sz = count($LN_Array);
$output = array();
//CSV Header
$output[] = array('Mother', 'DOB', 'Father', 'DOB', 'Son', 'DOB', 'Daughter', 'DOB');
for ($i = 0; $i < $NUM_RECORDS; $i++) {
    $surName = rand(1, $LN_Array_Sz - 1);
    $output[] = array($FN_Array[rand(1, $FN_Array_Sz - 1)][0] . ' ' . $LN_Array[rand(1, $LN_Array_Sz - 1)][0], date("m/d/Y"), $FN_Array[rand(1, $FN_Array_Sz - 1)][0] . ' ' . $LN_Array[$surName][0], date("m/d/Y"), $FN_Array[rand(1, $FN_Array_Sz - 1)][0] . ' ' . $LN_Array[$surName][0], date("m/d/Y"), $FN_Array[rand(1, $FN_Array_Sz - 1)][0] . ' ' . $LN_Array[$surName][0], date("m/d/Y"));
}
str_putcsv($output);
echo implode(PHP_EOL, $output);
function str_putcsv(&$array)
{
    $arraySz = count($array);
    for ($i = 0; $i < $arraySz; $i++) {
        $array[$i] = implode(',', $array[$i]);
    }
    return $array;
}
function csvToArray($fileName)
{
    $array = array();
开发者ID:scirelli,项目名称:jquerycsv,代码行数:31,代码来源:relationships.csv.php

示例7: csvToArray

function csvToArray($file, $delimiter)
{
    if (($handle = fopen($file, 'r')) !== FALSE) {
        $i = 0;
        while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
            for ($j = 0; $j < count($lineArray); $j++) {
                $arr[$i][$j] = $lineArray[$j];
                //echo "Columna: $lineArray[$j]\n";
            }
            $i++;
        }
        fclose($handle);
    }
    return $arr;
}
$data = csvToArray($feed, ';');
$dataNew = $data;
//print_r($data);
$count = count($data) - 1;
//echo "count: $count";
array_shift($dataNew);
array_shift($data);
//print_r($labels);
$keys = array("ref", "ordre", "nom", "desc", "thumb", "preu", "preuAntic", "tipus", "colors", "estoc");
//print_r($keys);
for ($i = 0; $i < $count; $i++) {
    $dataNew[$i][9] = array();
    //$dataNew[$i][9] = array($dataNew[$i][8] => array("talles" => array(), "imatges" => array()));
    array_splice($dataNew[$i], 10, 5);
    if ($dataNew[$i][0] == "") {
        array_splice($dataNew, $i, 1);
开发者ID:raulbarbado,项目名称:mrjen,代码行数:31,代码来源:csvtojson.php

示例8: while

{
    if (($handle = fopen($file, 'r')) !== FALSE) {
        $i = 0;
        while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
            for ($j = 0; $j < count($lineArray); $j++) {
                $arr[$i][$j] = $lineArray[$j];
            }
            $i++;
        }
        fclose($handle);
    }
    return $arr;
}
// Do it
$dataX = csvToArray($feedX, ',');
$dataY = csvToArray($feedY, ',');
// Set number of elements (minus 1 because we shift off the first row)
$count = count($dataX) - 1;
//Use first row for names
$labels = array_shift($dataX);
$labels = array_shift($dataY);
foreach ($labels as $label) {
    $keys[] = $label;
}
// Bring it all together
for ($j = 0; $j < $count; $j++) {
    $dX = array_combine($keys, $dataX[$j]);
    $arrayX[$j] = $dX;
    $dY = array_combine($keys, $dataY[$j]);
    $arrayY[$j] = $dY;
}
开发者ID:updewsprado,项目名称:dewslandslide-htdocs,代码行数:31,代码来源:getPosPlot.php

示例9: str_replace

 // Generate CSV
 $CSVFileName = str_replace(".xlsx", ".csv", $filename);
 $CSVFileName = str_replace("excel/", "csv/", $CSVFileName);
 $excel = PHPExcel_IOFactory::load($filename);
 $writer = PHPExcel_IOFactory::createWriter($excel, 'CSV');
 $writer->setDelimiter(",");
 //$writer->setEnclosure("");
 //$writer->setLineEnding("\r\n");
 $writer->setSheetIndex(0);
 $writer->save($CSVFileName);
 // Generate JSON
 $JSONFileName = str_replace(".csv", ".json", $CSVFileName);
 $JSONFileName = str_replace("csv/", "json/", $JSONFileName);
 $keys = array();
 $newArray = array();
 $data = csvToArray($CSVFileName, ',');
 $count = count($data) - 1;
 $labels = array_shift($data);
 foreach ($labels as $label) {
     $keys[] = $label;
 }
 $keys[] = 'id';
 for ($i = 0; $i < $count; $i++) {
     $data[$i][] = $i;
 }
 for ($j = 0; $j < $count; $j++) {
     $d = array_combine($keys, $data[$j]);
     $newArray[$j] = $d;
 }
 $JSONVersion = json_encode($newArray);
 $fp = fopen($JSONFileName, "w+");
开发者ID:aprewitt,项目名称:email-xlsx-to-csv-json-xml,代码行数:31,代码来源:job.php

示例10: getTombstone

 private function getTombstone($title)
 {
     if (!PreEighthRenderer::$titleToTombstone) {
         PreEighthRenderer::$titleToTombstone = csvToArray('data/preEighth/titleToTombstone.csv');
     }
     return array_key_exists((string) strtolower($title), PreEighthRenderer::$titleToTombstone);
 }
开发者ID:kyuumeitai,项目名称:cardgen,代码行数:7,代码来源:PreEighthRenderer.php

示例11: getFrameDir

 private function getFrameDir($title, $set, $settings)
 {
     if (!EighthRenderer::$titleToFrameDir) {
         EighthRenderer::$titleToFrameDir = csvToArray('data/eighth/titleToAlternateFrame.csv');
     }
     if (!EighthRenderer::$titleToTransform) {
         EighthRenderer::$titleToTransform = csvToArray('data/eighth/titleToTransform.csv');
     }
     $frameDir = @EighthRenderer::$titleToFrameDir[(string) strtolower($title)];
     if (!$frameDir) {
         $frameDir = 'transform-' . @EighthRenderer::$titleToTransform[(string) strtolower($title)];
     }
     $timeshifted = explode(',', $settings['card.timeshifted.frames']);
     if (!$frameDir || $frameDir == 'transform-') {
         $frameDir = "regular";
     }
     if ($frameDir == 'timeshifted' && in_array($set, $timeshifted) === FALSE) {
         $frameDir = "regular";
     }
     return $frameDir;
 }
开发者ID:kyuumeitai,项目名称:cardgen,代码行数:21,代码来源:EighthRenderer.php

示例12: csvToArray

function csvToArray($file, $delimiter)
{
    if (($handle = fopen($file, 'r')) !== FALSE) {
        $i = 0;
        while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
            for ($j = 0; $j < count($lineArray); $j++) {
                $arr[$i][$j] = $lineArray[$j];
            }
            $i++;
        }
        fclose($handle);
    }
    return $arr;
}
// Do it
$dataAlert = csvToArray($feed, ',');
// Set number of elements (minus 1 because we shift off the first row)
$count = count($dataAlert);
//Use first row for names
$labels = ["site", "node", "xalert", "yalert", "zalert"];
foreach ($labels as $label) {
    $keys[] = $label;
}
// Bring it all together
for ($j = 0; $j < $count; $j++) {
    $dX = array_combine($keys, $dataAlert[$j]);
    $arrayAlert[$j] = $dX;
}
// Print as JSON data
echo json_encode($arrayAlert);
?>
开发者ID:updewsprado,项目名称:dewslandslide-htdocs,代码行数:31,代码来源:getAlert.php

示例13: array

         if ($confirm_name_response == 'no_possible_matches') {
             $no_matches = true;
             $rejected_all = true;
         } else {
             if (!$reset_match) {
                 $confirmed_user_name = $confirm_name_response;
             }
         }
     }
 }
 $feed = 'https://docs.google.com/spreadsheets/d/1qYMG2XVmaK2GQMYATqCxa_kZu-ZptjUHF_o94_rKw2k/pub?gid=509740763&single=true&output=csv';
 $keys = array();
 //Array for Column Titles\
 $myArr = array();
 // Final Array
 $data = csvToArray($feed, ',');
 $count = count($data) - 1;
 //Store Column Titles
 $labels = array_shift($data);
 foreach ($labels as $label) {
     $keys[] = $label;
 }
 //Creat ID's
 $keys[] = 'id';
 for ($i = 0; $i < $count; $i++) {
     $data[$i][] = $i;
 }
 //Combine Keys and Values
 for ($j = 0; $j < $count; $j++) {
     $d = array_combine($keys, $data[$j]);
     $myArr[$j] = $d;
开发者ID:esrutledge,项目名称:mad-ten-theme,代码行数:31,代码来源:loop-profile-access.php

示例14: define

define("TO_EMAIL", "");
// Email notification recipient
define("SEND_TO_SLACK", true);
// Enable/Disable instant slack notification
define("SLACK_CHANNEL", "#general");
// Slack Channel
define("SLACK_WEBHOOK_URL", "");
// Slack Webhook Url
define("SEND_DAILY_EMAIL", true);
// Send daily notification summary to Email
define("SEND_DAILY_SLACK", true);
// Send daily notification summary to Slack
define("STATUS_SOURCE", "status.log");
// Status Log File
/* End Config */
$data = csvToArray();
$result = prepareRunGoogle($data);
if (SEND_TO_EMAIL) {
    resultsToEmail($result);
}
if (SEND_TO_SLACK) {
    resultsToSlack($result);
}
updateLog($data, $result);
function csvToArray()
{
    if (!file_exists(CSV_SOURCE) || !is_readable(CSV_SOURCE)) {
        // Check source and email error if issue occurs
        mail(TO_EMAIL, 'CSV Unreadable', 'Warning - URL Status Checker CSV "' . CSV_SOURCE . '" is unreadable/not found.');
    }
    // Save data to array $data
开发者ID:torican,项目名称:URL-Status-Checker,代码行数:31,代码来源:index.php

示例15: generate_json

function generate_json($doc, $bool)
{
    $keys = array();
    $array = array();
    $csv = csvToArray($doc, ',');
    // Set number of elements (minus 1 because we shift off the first row)
    $count = count($csv) - 1;
    //Use first row for names
    $labels = array_shift($csv);
    foreach ($labels as $label) {
        $keys[] = $label;
    }
    // Bring it all together
    for ($j = 0; $j < $count; $j++) {
        $d = array_combine($keys, $csv[$j]);
        $nid = '';
        if ($bool == true) {
            $id = $d['RIC.'];
            $pieces = explode(' ', $id);
            switch ($pieces[0]) {
                case 'C':
                    $auth = 'crl';
                    break;
                case 'SA':
                    $auth = 'sa';
                    break;
                case 'SS':
                    $auth = 'ss';
                    break;
                case 'E':
                    $auth = 'el';
                    break;
                case 'G':
                    $auth = 'ge';
                    break;
            }
            $nid = 'ric.4.' . $auth . '.' . strtolower($pieces[2]);
        }
        if (strlen($nid) > 0) {
            $x = $nid;
        } else {
            $x = $j;
        }
        $array[$x] = $d;
    }
    return $array;
}
开发者ID:AmericanNumismaticSociety,项目名称:migration_scripts,代码行数:47,代码来源:csv-to-nm.php


注:本文中的csvToArray函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。