當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CSV::setContent方法代碼示例

本文整理匯總了PHP中CSV::setContent方法的典型用法代碼示例。如果您正苦於以下問題:PHP CSV::setContent方法的具體用法?PHP CSV::setContent怎麽用?PHP CSV::setContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CSV的用法示例。


在下文中一共展示了CSV::setContent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: processStep4

function processStep4($option)
{
    global $database;
    //Get hidden data
    $separator = mosGetParam($_REQUEST, 'separator', ',');
    $convertUTF8 = mosGetParam($_REQUEST, 'csv_utf8', 0);
    //fault here
    $fileName = mosGetParam($_REQUEST, 'filename', '');
    $columns = mosGetParam($_REQUEST, 'columns', null);
    $fields = mosGetParam($_REQUEST, 'fields', null);
    $globalColumns = mosGetParam($_REQUEST, 'global_columns', null);
    $globalValues = mosGetParam($_REQUEST, 'global_value', null);
    //Get global setting
    $authorId = mosGetParam($_REQUEST, 'author_id', 0);
    $sectionId = mosGetParam($_REQUEST, 'section_id', 0);
    $categoryId = mosGetParam($_REQUEST, 'category_id', 0);
    $published = mosGetParam($_REQUEST, 'published', 0);
    $metaKeys = mosGetParam($_REQUEST, 'meta_keys', '');
    $metaDes = mosGetParam($_REQUEST, 'meta_des', '');
    $createdDate = mosGetParam($_REQUEST, 'created_date', '');
    $publishUpDate = mosGetParam($_REQUEST, 'publish_up_date', '');
    $publishDownDate = mosGetParam($_REQUEST, 'publish_down_date', '');
    $access = mosGetParam($_REQUEST, 'access', 0);
    $state = mosGetParam($_REQUEST, 'state', 0);
    //Import data now, go to final step
    $rowContent = new mosContent($database);
    //Get all data
    $arrContentFieldName = array();
    $arrContentFieldSTT = array();
    $arrJreviewFieldName = array();
    $arrJreviewFieldSTT = array();
    $totalColumn = count($columns);
    //Mark the ignore field lists
    $arrIgnores = array();
    for ($i = 0; $i < $totalColumn; $i++) {
        $column = $columns[$i];
        $field = $fields[$i];
        $arrField = explode(".", $field);
        $tableName = $arrField[0];
        $fieldName = $arrField[1];
        if ($fieldName != 'ignore') {
            if ($tableName == "jos_content") {
                $arrContentFieldName[$i] = $fieldName;
                $arrContentFieldSTT[] = $i;
            } else {
                $arrJreviewFieldName[$i] = $fieldName;
                $arrJreviewFieldSTT[] = $i;
            }
        } else {
            $arrIgnores[] = $i;
        }
    }
    //Set static content vaiable
    $arrGlobalSetting = array();
    $arrGlobalSetting["created_by"] = $authorId;
    $arrGlobalSetting["sectionid"] = $sectionId;
    $arrGlobalSetting["catid"] = $categoryId;
    $arrGlobalSetting["published"] = $published;
    $arrGlobalSetting["metakey"] = $metaKeys;
    $arrGlobalSetting["metadesc"] = $metaDes;
    $arrGlobalSetting["created"] = $createdDate;
    $arrGlobalSetting["publish_up"] = $publishUpDate;
    $arrGlobalSetting["publish_down"] = $publishDownDate;
    $arrGlobalSetting["access"] = $access;
    $arrGlobalSetting["state"] = $state;
    //CustomGlobla Varaible
    $totalGlobalFields = count($globalColumns);
    $arrJreviewSettings = array();
    for ($i = 0; $i < $totalGlobalFields; $i++) {
        $column = $globalColumns[$i];
        $value = $globalValues[$i];
        $arrField = explode(".", $column);
        $field = $arrField[1];
        $arrJreviewSettings[$field] = $value;
    }
    //Attributes
    $params = mosGetParam($_POST, 'params', '');
    if (is_array($params)) {
        $txt = array();
        foreach ($params as $k => $v) {
            if (get_magic_quotes_gpc()) {
                $v = stripslashes($v);
            }
            $txt[] = "{$k}={$v}";
        }
        $attribs = implode("\n", $txt);
    }
    //Read the file here
    //Open File and read the correlative data
    //cell separator, row separator, value enclosure
    $csv = new CSV($separator, "\r\n", '"');
    //parse the string content
    $csv->setContent(file_get_contents(PATH_ROOT . "images/csv_import/{$fileName}"));
    //returns an array with the CSV data
    if ($convertUTF8) {
        $csvArray = utf8_encode_mix($csv->getArray());
    } else {
        $csvArray = $csv->getArray();
    }
    //Read the header
//.........這裏部分代碼省略.........
開發者ID:bizanto,項目名稱:Hooked,代碼行數:101,代碼來源:admin.csv_import.php


注:本文中的CSV::setContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。