更改 php 生成 css 字段外壳和字段分隔符



我们使用以下脚本,但它会生成一个带有字段分隔符,和字段外壳"的 csv 文件。但我想将其更改为以下内容:

现场机箱:'

字段分隔符:;

我们怎样才能改变这种状况?

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
ini_set('memory_limit', '12288M');
require('app/Mage.php');
Mage::app();
$file_path = "var/import/productname.csv";
$mage_csv = new Varien_File_Csv();
$products_row = $_parseObjects = $_additional = [];
$_product = null;
$_storeId = Mage::app()->getStore()->getId();
$_config = Mage::getModel('seo/config');
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setPageSize(2000)->setCurPage(1);
foreach ($products as $product) {
    global $_product;
    $_product = $product;
    $seo = getCurrentSeo();
    $productnamestring = $seo->getTitle();
    $findseo = array('/h+inch (?:(i[357])-w+|h+w+)?/', '/(w+)#w+/', '/(^| )(.{4,}) (.*)2/', '/s*-s*$/');
    $replaceseo = array('" $1', '$1', '$1$2 $3', '');
    $productnamingseo = preg_replace($findseo, $replaceseo, $productnamestring);
    $data = array();
    $data['sku'] = $product->getSku();
    $data['name'] = $productnamingseo;
    $products_row[] = $data;
}
$mage_csv->saveData($file_path, $products_row);
echo 'Done!';
您可以使用

以下内容:

$mage_csv->setDelimiter(';');
$mage_csv->setEnclosure("'");
$mage_csv->saveData($file_path, $products_row);

最新更新