Jump to content

2 single quotes becoming 1 single quote


lordrt

Recommended Posts

Am using the following script to parse data from a csv, but the trouble is that a 2 single quote string is becoming a single quoted one:

 

script calling csv:

<?php

// import php file: import_article.php
require("import_article.php");


mysql_connect("127.0.0.1", "root", "") or die (mysql_error());
mysql_select_db("drupal_zenhaeusern") or die (mysql_error());

// read first .csv file encountered

$path = "sites/path/files/";
$sfile = "*.csv";

foreach (glob($path.$sfile) as $filename){
    echo $filename . "<br/>";
    $file = fopen($filename, 'r');
    while (($data = fgetcsv($file, 0, ",", "'")) !== False)
    {
        //$data = str_replace("'", " ", $data);
        foreach ($data as $k => $v)
        {
            //$data[$k] = ltrim($v, "'");
            //$data[$k] = rtrim($v, "'");
            echo htmlentities($data[$k], ENT_QUOTES)."\n";
        }
 //$data = implode(" ", $data);
        //echo $data[0] ."\n". $data[1] ."\n". $data[2] ."\n". $data[3] ."\n". $data[4] ."\n". $data[5] ."\n". $data[6]. "<br/>";
        //echo $data ."\n";
        ImportArticle($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6]);
    }
    echo "read complete";
    fclose($file);
    // unlink ($filename);
}
echo "closing connection";
mysql_close();
?>

 

DAta from csv

184, 'Mini ballon Graham', '<p>Mini ballon,'' Graham</p>',0.6, ' ', ' ', 0

 

browser return value:

insert into node_revisions(nid, vid, title, body, teaser) values (55, 55, 'Mini ballon Graham', '<p>Mini ballon,' Graham</p>', '<p>Mini ballon,' Graham</p>')

 

As seen above, the red colored quote in the insert part is only single quote, while it should have been as in the csv file one, with only the start and end quotes of each data removed , and thus is not inserting in the table

Link to comment
https://forums.phpfreaks.com/topic/169563-2-single-quotes-becoming-1-single-quote/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.