I am having a bit of trouble right now.. I'm trying to create a php file to export products to a csv file and it's working pretty good.

My only problem is with the product description. I'm using the getDescription() function to get my product descriptions, but it inserts line breaks into the csv file, which won't work on import obviously. I'm trying to remove all line breaks and stuff, since I only want plain text for the descriptions.

I've tried using strip_tags, but it's doing weird things.. When I use strip_tags, the whole description is in one line like I want it to, but it also replaces all spaces with + and removes any of the German characters ..

Let me just show you what I mean. Here's the code I'm using:

error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);

$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToFilter('status', 1);//optional for only enabled products
//$products->addAttributeToFilter('visibility', 4);//optional for only visible products
$fp = fopen('export_moebelde.csv', 'w');
$csvHeader = array("art_nr", "art_name", "art_beschreibung", "art_url",     "art_img_url","art_waehrung","art_preis","art_lieferkosten");
fputcsv( $fp, $csvHeader,";");
foreach ($products as $product){
  $art_nr = $product->getSku();
  $art_name = $product->getName();
  $art_beschreibung = urlencode( strip_tags($product->getDescription()) );
  $art_url = $product->getProductUrl();
  $art_img_url = $product->getThumbnail();
  $art_waehrung = "EUR";
  $art_preis = $product->getFinalPrice();
  $art_lieferkosten = "0";
//  $category_ids = implode(',', $product->getCategoryIds());
fputcsv($fp, array($art_nr, $art_name, $art_beschreibung, $art_url, $art_img_url, $art_waehrung, $art_preis, $art_lieferkosten), "|");

And here's the result:

jkfalieg-xxl|"Fiam Amigo XXL"|XXL+Liege+mit+Gestell+aus+Aluminium.Bezug%3A+Textiline+%28wetterfest+und+uv-best%C3%A4ndig%29.%0D%0A|https://www.zeitlos-einrichtung.info/fiam-amigo-xxl.html?SID=toarp61ih56l7610u5uf786qa0|/f/i/fiamamigo.jpg|EUR|195.0000|0

I know the product URL and the tumbnail URL need some work, but right now I just don't have a clue what to do about the description!

I appreciate any suggestions or tips you guys may have for me!

1 Answer 1


It should work. If you enclose your description by "" and escape every " inside as "" you shouldn't have any problem. This is as CSV works (at least for me)

  • Thanks for the answer! I found the problem, wasn't with the strip_tags, but I had to lose the urlencode... Got that from some tutorial and somehow didn't remove it, which is why I had plus signs for spaces. Feb 24, 2015 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.