2016-08-12 71 views
1

我寫了一個代碼來添加sku的產品說明。現在腳本工作正常,但所有格式似乎都丟失了,因爲在csv中,添加到產品的描述是部分的(似乎它在任何特殊字符後刪除字符串)。將說明添加到產品表單csv文件

我的代碼:

require_once 'app/Mage.php'; 
umask(0); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
if (($handle = fopen("Witedescriptions.csv", "r")) !== FALSE) { 
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 
     $desc =$data[1]; 
     $sku = $data[2]; 
     $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); 
     $product->setDescription($desc); 
     $product->save(); 
    } 
    fclose($handle); 
} 

的CSV文件struture

Sno. , Description , Sku 

上描述

Test this is dummy data abd’s base is of a slim yellow gold halo that easily fits on a finger. 

list here 
• list 1 
• list 2 

當我運行的腳本樣本數據,產品具有以下唯一的數據:

Test this is dummy data abd 

它似乎有逃避一些字符我試圖用我的descrition設置爲「黃金的價格在美國」,但在管理產品,我剛剛拿到「金牌」

+0

我測試你的代碼,並解析CSV文件,並獲取值時,有沒有問題。問題應該在這裏:'$ product-> setDescription($ desc);',所以看看這個函數。我想你需要從描述中刪除/替換有問題的字符,然後將其存儲到數據庫中。 –

+0

它只是的東西無法找到爲什麼即使添加addslahes不起作用 – gaurav

回答

0

而且你的代碼逃脫引號使用和addslashes :

$desc = addslashes($data[1]); 

但這並不意味着他們需要刪除輸出。

0

使用這些函數可以跳轉'你的字符串。

$data = trim(htmlentities(strip_tags($data))); 

$data = mysql_real_escape_string($data); 

public function filter($data) 
    { 
     $data = trim(htmlentities(strip_tags($data))); 
     // print_r($data); 
     if (get_magic_quotes_gpc()){ 
      // print_r($data); 
      $data = stripslashes($data); 
      // print_r($data); 
      $data = mysql_real_escape_string($data); 
      // print_r($data); 
     } 
     return $data;  
    } 
+0

沒有工作,我得到空白內容 – gaurav

+0

好吧,讓我檢查它在我身邊 –

+0

好的請做.................. .... – gaurav

相關問題