Replace escaped double quotes in CSV
NickName:Akhilesh Ask DateTime:2022-06-28T19:39:25

Replace escaped double quotes in CSV

I am reading content from a csv. I want to replace the single and double quotes from the data. I have tried the following code but is not working.

    $resource = fopen($this->csv_file, 'r');
    while (($data = fgetcsv($resource, 10000, ',')) !== false) {
    $custom = $data[10];
    $custom = str_replace('"', 'in',$custom);
    $custom = str_replace("'", 'ft',$custom);

$custom has the value of a column from CSV. It seems that double quotes are escaped in CSV using double quotes like 15""x5000' How can I do this in PHP?

var_dump is showing string '15"x5000' Produce Film' (length=22) CSV in editor is showing "Select the product size and enter the quantity|15""x5000' Produce Film"

Copyright Notice:Content Author:「Akhilesh」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72785731/replace-escaped-double-quotes-in-csv

More about “Replace escaped double quotes in CSV” related questions

Replace escaped double quotes in CSV

I am reading content from a csv. I want to replace the single and double quotes from the data. I have tried the following code but is not working. $resource = fopen($this->csv_file, 'r');

Show Detail

How to replace double quotes by escaped double quote in awk?

In awk how can I replace all double quotes by escaped double quotes? The dog is "very" beautiful would become The dog is \"very\" beautiful I've seen this answer (Using gsub to replace a double.

Show Detail

Replace special character with double double quotes

I have a text file with the some special character $, which needs to be replaced by double double quotes. I am using a bat file in which I invoke powershell.exe and write the replace command. Below...

Show Detail

Replace all quotes in a string with escaped quotes?

Given a string in python, such as: s = 'This sentence has some "quotes" in it\n' I want to create a new copy of that string with any quotes escaped (for further use in Javascript). So, for example,

Show Detail

Parsing CSV file with multiline fields and escaped double quotes

What is the best way to parse a CSV file with multiline fields and escaped quotes? For example, this CSV First field of first row,"This field is multiline but that's OK because it's enclosed in ...

Show Detail

Regex to replace non escaped Quotes

After having some trouble building a json string I discovered some text in my database containing double quotes. I need to replace the quotes with their escaped equivalents. This works: function e...

Show Detail

Replacing escaped double quotes by double quotes in R

I am writing some html code to an SQL databse using RMySQL (but I guess my problem is rather a general R question than really related to SQL or RMySQL). So I am trying something like this: con <-

Show Detail

Pandas dataframe to_csv escape double quotes

I am trying to export pandas dataframe in csv. Some of data contains double quotes and I can't get it escaped properly. import pandas as pd from io import StringIO inp = [{'c1':10, 'c2':'some text...

Show Detail

RegEx with escaped double quotes

I have the following RegEx that mostly works for my use cases (CLI command interpreter): [^\s"]+|"[^"\\]*(?:\\.[^"\\]*)*" It matches the following scenarios (and separates parts successfully): foo

Show Detail

Match and replace a word not in quotes (string contains escaped quotes)

How can I replace all occurrences of a particular word from a given string with another, provided the word does not occur within quotes. Note that the input string will most likely contain escaped ...

Show Detail