【问题标题】:fputcsv putting quotes where it shouldn'tfputcsv 将引号放在不应该的地方
【发布时间】:2011-01-28 16:21:24
【问题描述】:

我正在编写一个脚本来将产品导出到 Google Base...问题是,当我使用以下代码时,in stock 会输出为 "in stock" 而 Google 无法识别它,它只会在没有引号。我不知道在不包含引号的情况下如何做到这一点。

                        $row = array(
                            'new',
                            $product->getSku().'-'.$vehicle->getId(),
                            'https://www.domain.com/vehicles/'.str_replace(' ', '-', $make->getName()).'/'.str_replace(' ', '-', $model->getName()).'/'.$year.'/'.$product->getId(),
                            $this->tru->config->get('root.cdn.url').'-products/'.$product->getPicture(),
                            $product->getSellPrice(),
                            $title,
                            $year,
                            'in stock',
                            $product->getFCCID(),
                            'Visa,Mastercard,Discover,AmericanExpress',
                            'US::Ground:4.95,CA::Ground:28.95',
                            'small',
                            'Vehicles & Parts > Automotive Locking Systems > Remote Keyless Systems'
                        );

                        fputcsv($output, $row, $seperatorValue);

【问题讨论】:

  • $seperatorValue 的值是多少?如果你在 $row 数组中使用双引号而不是单引号会发生什么?
  • $seperatorValue = chr(9); - 它转义双引号
  • ? chr(9) 这不是空格吗? echo "字符:|".chr(9)."|\n";

标签: php fputcsv


【解决方案1】:

我认为编写自己的函数而不是使用 fputcsv() 会更好

下面几行代码

$output = fopen("path/to/your/file.csv", "a+");

$line = join(',', $row);

fwrite($output, $line);

fclose($output);

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多