Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 346207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:09:20+00:00 2026-05-12T11:09:20+00:00

Ok, I have a csv file like this: 14 ; 1234,56 ; 10203 ;

  • 0

Ok, I have a csv file like this:

14 ; 1234,56 ; 10203 ; "ABC" ; "DFG" ; "Lorem \n ipsum \n dolor sit" \n
15 ; 234,16 ; 10204 ; "ABC" ; "DFG" ; "Lorem \n ipsum \n dolor sit" \n
16 ; 1234,15 ; 10304 ; "CCC" ; "DFG" ; "Lorem ipsum/dolor \n sit amet\consec" \n

and so on…

The file has almost 550000 lines.
How do I replace all \n characters inside double quotes at once?

I’m using PHP 5. Could it be done by preg_replace()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:09:20+00:00Added an answer on May 12, 2026 at 11:09 am

    I don’t know if you’re using fgetcsv(), but you can configure it to recognize individual fields including quoted information.

    This way you can read your lines in one at a time and strip the new line characters at the field level rather than having to do an expensive RegEx operation on a large file all at once.

    Slightly modified php code example from the documentation (replaced delimiter with ‘;’):

    $row = 1;
    $handle = fopen("data.txt", "r");
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
    

    data.txt

    14 ; 1234,56 ; 10203 ; "ABC" ; "DFG" ; "text 
     text 
     more text"
    15 ; 234,16 ; 10204 ; "ABC" ; "DFG" ; "text 
     text 
     more text"
    

    This will be recognized as 2 lines instead of 6 because fgetcsv() will recognize the new line characters in the quotes as part of the field and not additional lines of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .csv file like this: stack2@domain.example,2009-11-27 01:05:47.893000000,domain.example,127.0.0.1 overflow@domain2.example,2009-11-27 00:58:29.793000000,domain2.example,255.255.255.0 overflow@domain2.example,2009-11-27 00:58:29.646465785,domain2.example,256.255.255.0 ...
I have a CSV file formatted just like this: name,color,tasty,qty apple,red,true,3 orange,orange,false,4 pear,greenish-yellowish,true,1 As
I have a csv file which looks like this $lines[0] = text, with commas,
So I have a CSV file that looks like this: 12345, Here is some
I have some lines in a CSV file like this: 1000001234,Account Name,0,0,3,711.32,0,0,18,629.64,22,340.96,COD,20,000.00,Some string,Some string
I have a csv file that looks something like this (actual file has many
i have a csv file like this: i,0 <-- 1st line f,1,2,3 <-- 2nd
I have a csv file that looks like this: 603629,0,ATLV0008,Vendor1,1942.60,11/04/2010,1942.60,9/1-9/30/10,EFT-JP 603627,2,ATLV0008,Vendor1,1242.40,11/04/2010,1242.40,7/1-7/31/10,EFT-JP 600023,0,FLD4V0003,Vendor2,1950.00,06/15/2010,1950.00,6/14/10 Request,EFT-JP 600024,0,FLD4V0003,Vendor2,1800.00,06/15/2010,1800.00,6/14/10
Hi i have a CSV file that contains rows like this Jacop , Assistant,150,75
I have a csv file which has a word for each row like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.