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


PHP csv_import_reader::get_delimiter方法代码示例

本文整理汇总了PHP中csv_import_reader::get_delimiter方法的典型用法代码示例。如果您正苦于以下问题:PHP csv_import_reader::get_delimiter方法的具体用法?PHP csv_import_reader::get_delimiter怎么用?PHP csv_import_reader::get_delimiter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在csv_import_reader的用法示例。


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

示例1: data_export_csv

/**
 * @global object
 * @param array $export
 * @param string $delimiter_name
 * @param object $database
 * @param int $count
 * @param bool $return
 * @return string|void
 */
function data_export_csv($export, $delimiter_name, $dataname, $count, $return=false) {
    global $CFG;
    require_once($CFG->libdir . '/csvlib.class.php');
    $delimiter = csv_import_reader::get_delimiter($delimiter_name);
    $filename = clean_filename("{$dataname}-{$count}_record");
    if ($count > 1) {
        $filename .= 's';
    }
    $filename .= clean_filename('-' . gmdate("Ymd_Hi"));
    $filename .= clean_filename("-{$delimiter_name}_separated");
    $filename .= '.csv';
    if (empty($return)) {
        header("Content-Type: application/download\n");
        header("Content-Disposition: attachment; filename=$filename");
        header('Expires: 0');
        header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
        header('Pragma: public');
    }
    $encdelim = '&#' . ord($delimiter) . ';';
    $returnstr = '';
    foreach($export as $row) {
        foreach($row as $key => $column) {
            $row[$key] = str_replace($delimiter, $encdelim, $column);
        }
        $returnstr .= implode($delimiter, $row) . "\n";
    }
    if (empty($return)) {
        echo $returnstr;
        return;
    }
    return $returnstr;
}
开发者ID:nottmoo,项目名称:moodle,代码行数:41,代码来源:lib.php

示例2: get_encoded_delimiter

 /**
  * Get encoded delimiter character
  *
  * @global object
  * @param string separator name
  * @return string encoded delimiter char
  */
 static function get_encoded_delimiter($delimiter_name)
 {
     global $CFG;
     if ($delimiter_name == 'cfg' and isset($CFG->CSV_ENCODE)) {
         return $CFG->CSV_ENCODE;
     }
     $delimiter = csv_import_reader::get_delimiter($delimiter_name);
     return '&#' . ord($delimiter);
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:16,代码来源:csvlib.class.php

示例3: glossary_generate_export_csv

/**
 *
 * @global object
 * @param array $entries
 * @param array $aliases
 * @param array $categories
 * @return string
 */
function glossary_generate_export_csv($entries, $aliases, $categories) {
    global $CFG;
    $csv = '';
    $delimiter = '';
    require_once($CFG->libdir . '/csvlib.class.php');
    $delimiter = csv_import_reader::get_delimiter('comma');
    $csventries = array(0 => array(get_string('concept', 'glossary'), get_string('definition', 'glossary')));
    $csvaliases = array(0 => array());
    $csvcategories = array(0 => array());
    $aliascount = 0;
    $categorycount = 0;

    foreach ($entries as $entry) {
        $thisaliasesentry = array();
        $thiscategoriesentry = array();
        $thiscsventry = array($entry->concept, nl2br($entry->definition));

        if (array_key_exists($entry->id, $aliases) && is_array($aliases[$entry->id])) {
            $thiscount = count($aliases[$entry->id]);
            if ($thiscount > $aliascount) {
                $aliascount = $thiscount;
            }
            foreach ($aliases[$entry->id] as $alias) {
                $thisaliasesentry[] = trim($alias);
            }
        }
        if (array_key_exists($entry->id, $categories) && is_array($categories[$entry->id])) {
            $thiscount = count($categories[$entry->id]);
            if ($thiscount > $categorycount) {
                $categorycount = $thiscount;
            }
            foreach ($categories[$entry->id] as $catentry) {
                $thiscategoriesentry[] = trim($catentry);
            }
        }
        $csventries[$entry->id] = $thiscsventry;
        $csvaliases[$entry->id] = $thisaliasesentry;
        $csvcategories[$entry->id] = $thiscategoriesentry;

    }
    $returnstr = '';
    foreach ($csventries as $id => $row) {
        $aliasstr = '';
        $categorystr = '';
        if ($id == 0) {
            $aliasstr = get_string('alias', 'glossary');
            $categorystr = get_string('category', 'glossary');
        }
        $row = array_merge($row, array_pad($csvaliases[$id], $aliascount, $aliasstr), array_pad($csvcategories[$id], $categorycount, $categorystr));
        $returnstr .= '"' . implode('"' . $delimiter . '"', $row) . '"' . "\n";
    }
    return $returnstr;
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:61,代码来源:lib.php

示例4: add_data

 /**
  * Add data to the temporary file in csv format
  *
  * @param array $row  An array of values.
  */
 public function add_data($row)
 {
     if (!isset($this->path)) {
         $this->set_temp_file_path();
         $this->fp = fopen($this->path, 'w+');
     }
     $delimiter = csv_import_reader::get_delimiter($this->delimiter);
     fputcsv($this->fp, $row, $delimiter, $this->csvenclosure);
 }
开发者ID:Burick,项目名称:moodle,代码行数:14,代码来源:csvlib.class.php

示例5: process_export

 /**
  *
  */
 public function process_export($range = self::EXPORT_PAGE)
 {
     global $CFG;
     require_once $CFG->libdir . '/csvlib.class.php';
     if (!($csvcontent = $this->get_csv_content($range))) {
         return;
     }
     $dataformname = $this->df->name;
     $delimiter = \csv_import_reader::get_delimiter($this->_delimiter);
     $filename = clean_filename("{$dataformname}-export");
     $filename .= clean_filename('-' . gmdate("Ymd_Hi"));
     $filename .= clean_filename("-{$this->_delimiter}_separated");
     $filename .= '.csv';
     $patterns = array("\n");
     $adjustments = array('');
     if ($this->_enclosure) {
         $patterns[] = $this->_enclosure;
         $adjustments[] = '&#' . ord($this->_enclosure) . ';';
     } else {
         $patterns[] = $delimiter;
         $adjustments[] = '&#' . ord($delimiter) . ';';
     }
     $returnstr = '';
     foreach ($csvcontent as $row) {
         foreach ($row as $key => $column) {
             $value = str_replace($patterns, $adjustments, $column);
             $row[$key] = $this->_enclosure . $value . $this->_enclosure;
         }
         $returnstr .= implode($delimiter, $row) . "\n";
     }
     // Convert encoding.
     $returnstr = mb_convert_encoding($returnstr, $this->_encoding, 'UTF-8');
     header("Content-Type: application/download\n");
     header("Content-Disposition: attachment; filename=\"{$filename}\"");
     header('Expires: 0');
     header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
     header('Pragma: public');
     echo $returnstr;
     exit;
 }
开发者ID:vaenda,项目名称:moodle-mod_dataform,代码行数:43,代码来源:csv.php

示例6: data_export_csv

function data_export_csv($export, $delimiter_name, $dataname, $count)
{
    $delimiter = csv_import_reader::get_delimiter($delimiter_name);
    $filename = clean_filename("{$dataname}-{$count}_record");
    if ($count > 1) {
        $filename .= 's';
    }
    $filename .= clean_filename('-' . gmdate("Ymd_Hi"));
    $filename .= clean_filename("-{$delimiter_name}_separated");
    $filename .= '.csv';
    header("Content-Type: application/download\n");
    header("Content-Disposition: attachment; filename={$filename}");
    header('Expires: 0');
    header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
    header('Pragma: public');
    $encdelim = '&#' . ord($delimiter) . ';';
    foreach ($export as $row) {
        foreach ($row as $key => $column) {
            $row[$key] = str_replace($delimiter, $encdelim, $column);
        }
        echo implode($delimiter, $row) . "\n";
    }
    die;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:24,代码来源:export.php


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