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


PHP FLEXIUtilities::csvstring_to_array方法代码示例

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


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

示例1: importcsv


//.........这里部分代码省略.........
                // ******************************************************************************************************
                // Retrieve CSV file format variables, EXPANDING the Escape Characters like '\n' ... provided by the form
                // ******************************************************************************************************
                $pattern = '/(?<!\\\\)(\\\\(?:n|r|t|v|f|[0-7]{1,3}|x[0-9a-f]{1,2}))/i';
                $replace = 'eval(\'return "$1";\')';
                $conf['mval_separator'] = preg_replace_callback($pattern, function ($matches) {
                    $r = $matches[1];
                    eval("\$r = \"{$r}\";");
                    return $r;
                }, $conf['mval_separator']);
                $conf['mprop_separator'] = preg_replace_callback($pattern, function ($matches) {
                    $r = $matches[1];
                    eval("\$r = \"{$r}\";");
                    return $r;
                }, $conf['mprop_separator']);
                $conf['field_separator'] = preg_replace_callback($pattern, function ($matches) {
                    $r = $matches[1];
                    eval("\$r = \"{$r}\";");
                    return $r;
                }, $conf['field_separator']);
                $conf['enclosure_char'] = preg_replace_callback($pattern, function ($matches) {
                    $r = $matches[1];
                    eval("\$r = \"{$r}\";");
                    return $r;
                }, $conf['enclosure_char']);
                $conf['record_separator'] = preg_replace_callback($pattern, function ($matches) {
                    $r = $matches[1];
                    eval("\$r = \"{$r}\";");
                    return $r;
                }, $conf['record_separator']);
                // ****************************************************
                // Read & Parse the CSV file according the given format
                // ****************************************************
                $contents = FLEXIUtilities::csvstring_to_array(file_get_contents($csvfile), $conf['field_separator'], $conf['enclosure_char'], $conf['record_separator']);
                // Basic error checking, for empty data
                if (!$contents || count($contents[0]) <= 0) {
                    $app->enqueueMessage('CSV file format is not correct!', 'error');
                    $app->redirect($link);
                }
                // ********************************************************************************
                // Get field names (from the header line (row 0), and remove it form the data array
                // ********************************************************************************
                $conf['columns'] = flexicontent_html::arrayTrim($contents[0]);
                unset($contents[0]);
                $q = 'SELECT id, name, field_type, label FROM #__flexicontent_fields AS fi' . ' JOIN #__flexicontent_fields_type_relations AS ftrel ON ftrel.field_id = fi.id AND ftrel.type_id=' . $conf['type_id'];
                $db->setQuery($q);
                $conf['thefields'] = $db->loadObjectList('name');
                unset($conf['thefields']['tags']);
                // Prevent Automated Raw insertion of tags, we will use special code
                // ******************************************************************
                // Check for REQUIRED columns and decide CORE property columns to use
                // ******************************************************************
                $core_props = array();
                if ($conf['id_col'] && !in_array('id', $conf['columns'])) {
                    $app->enqueueMessage('CSV file lacks column <b>\'id\'</b> (Item ID)', 'error');
                    $app->redirect($link);
                } else {
                    if ($conf['id_col']) {
                        $core_props['id'] = 'Item ID';
                    }
                }
                if (!in_array('title', $conf['columns'])) {
                    $app->enqueueMessage('CSV file lacks column <b>\'title\'</b>', 'error');
                    $app->redirect($link);
                }
                $core_props['title'] = 'Title (core)';
开发者ID:nettdotkomm,项目名称:flexicontent-cck,代码行数:67,代码来源:import.php


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