我们使用以下脚本,但是该脚本将生成带有字段分隔符,
和字段附件"
的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!';
答案 0 :(得分:3)
您可以使用以下内容:
$mage_csv->setDelimiter(';');
$mage_csv->setEnclosure("'");
$mage_csv->saveData($file_path, $products_row);