I could use your help once again... I'm currently building a php export to hand our products off to a comparison website. One of their requirements is that every string is wrapped in double quotes.

I've tried different things, but I'm still running into problems here. I don't know why it's doing what it's doing and am open to any suggestions y'all might have!

First thing I tried was simply putting

$art_nr = '"'.$product->getSku().'"';

And then I tried using the strip method to ensure there aren't any quotes already around the string...

$art_farbe = '"'.trim($art_farbe,'"').'"';

But the result is always the same and looks like this:

"""jkfalieg-xxl"""|"Fiam Amigo XXL"|"XXL Liege mit Gestell aus Aluminium. Bezug: Textiline (wetterfest und uv-beständig)., "|"""https://www.zeitlos-einrichtung.info/fiam-amigo-xxl.html"""|"""https://www.zeitlos-einrichtung.info/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/f/i/fiamamigo.jpg"""|https://www.zeitlos-einrichtung.info/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/f/i/fiamamigo.jpg|||||||||"""Aluminium"""|"""EUR"""|"""195.0000"""|"""0"""||""""""|"""75"""|"""cm"""|"""207"""|"""cm"""|"""33"""|"""cm"""|""""""|""""""

For everything I use one of the two methods mentioned above I get three double quotes in front and after the content of the string. The second and third column are working because I didn't to anything to them since they're automatically surrounded by double quotes since there's spaces in the string.

If someone has an idea how to fix this please let me know! :)

  • Try this : $art_nr = '\"'.$product->getSku().'\"'; Mar 2, 2015 at 11:56
  • 1
    What code/function are you using to eventually build the CSV like string? Could you add that to your question?
    – 7ochem
    Mar 2, 2015 at 12:04
  • I'm using the method fputcsv() Mar 4, 2015 at 12:05

2 Answers 2


I would recommend working with php native functions when building csv files. For example fputcsv would probably work for you. In this case you can define:

  1. The delimiter used in the csv (in your case |)
  2. What to enclose each entry with (in your case ")

Direct example from php.net

Example #1 fputcsv() example


$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd'),
    array('123', '456', '789'),
    array('"aaa"', '"bbb"')

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields);


The above example will write the following to file.csv:


@7ochem is probably the one to ask as to how to go about this with Magento's built in methods for exporting a collection of varien objects to CSV, however, you are in a good place with the code you have got and the underlying PHP csv functions of Magento's methods do not allow for all quotes around everything.

I suggest that you stick with arrays and once you have a 'row' iterate over it once to replace existing " marks with single quotes. This will work fine and should not matter for the porpoises of a comparison shopping site (except if you are using customary units for dimensions).

Now 'implode' your array 'row' with "|" and bolt on a " at the front and end. You should now have something clean with no double-escaped out double quotes there to break anything.


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.