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

  • SEARCH
  • Home
  • 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 8299293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:05:50+00:00 2026-06-08T16:05:50+00:00

Before I start, I know this is CSV and I know there is a

  • 0

Before I start, I know this is CSV and I know there is a function that exist build-in PHP.
I got the following pattern :

preg_match_all("/([^\"]|\"[^\"]*\")*?(r\n|\n\r|\r|\n)/i", $CSV, $Matches);

Who will parse something like that :

Country,Region/State,City,"Zip/Postal Code\n From","Zip/Postal Code To","Weight From","Weight To","Shipping Price","Delivery Type"\n\r
CAN,*,,,,0.0000,4999.0000,29.7500,Priority\n\r
CAN,*,,,,10000.0000,19999.0000,35.5000,Express\n\r
CAN,*,,,,0.0000,4999.0000,19.7500,Express\n\r
CAN,*,,,,20000.0000,99999999.9999,59.0000,Priority\n\r
CAN,*,,,,5000.0000,9999.0000,34.7500,Priority\n\r
CAN,*,,,,20000.0000,99999999.9999,41.5000,Express\n\r
CAN,*,,,,5000.0000,9999.0000,24.4500,Express\n\r
CAN,*,,,,10000.0000,19999.0000,48.0000,Priority\n\r
CAN,*,,,,10000.0000,19999.0000,29.7500,Standard\n\r
CAN,*,,,,20000.0000,99999999.9999,36.5000,Standard\n\r
CAN,*,,,,500.0000,9999.0000,20.3500,Standard\n\r
CAN,*,,,,90.0000,499.0000,9.7500,Standard\n\r
CAN,*,,,,50.0000,89.0000,1.8000,Standard\n\r
CAN,*,,,,30.0000,49.0000,1.5000,Standard\n\r
CAN,*,,,,0.0000,29.0000,1.0000,Standard\n\r
USA,*,,,,20000.0000,99999999.9999,160.0000,Express\n\r
USA,*,,,,10000.0000,14999.0000,76.0000,Express\n\r
USA,*,,,,1000.0000,4999.0000,42.0000,Express\n\r
USA,*,,,,15000.0000,19999.0000,155.0000,Priority\n\r
USA,*,,,,5000.0000,9999.0000,94.0000,Priority\n\r
USA,*,,,,0.0000,999.0000,75.5000,Priority\n\r
USA,*,,,,15000.0000,19999.0000,98.0000,Express\n\r
USA,*,,,,5000.0000,9999.0000,61.5000,Express\n\r
USA,*,,,,0.0000,999.0000,40.0000,Express\n\r
USA,*,,,,20000.0000,99999999.9999,230.0000,Priority\n\r
USA,*,,,,10000.0000,14999.0000,120.0000,Priority\n\r
USA,*,,,,1000.0000,4999.0000,61.5000,Priority\n\r
USA,*,,,,500.0000,999.0000,25.5000,Standard\n\r
USA,*,,,,90.0000,499.0000,13.3500,Standard\n\r
USA,*,,,,50.0000,89.0000,3.0000,Standard\n\r
USA,*,,,,30.0000,49.0000,1.8000,Standard\n\r
USA,*,,,,0.0000,29.0000,1.5000,Standard\n\r

The resulst I get is similar to :

[2] => Array
    (
    )

[3] => Array
    (
        [0] => CAN
        [1] => *
        [2] => 
        [3] => 
        [4] => 
        [5] => 10000.0000
        [6] => 19999.0000
        [7] => 35.5000
    )

[4] => Array
    (
    )

[5] => Array
    (
        [0] => CAN
        [1] => *
        [2] => 
        [3] => 
        [4] => 
        [5] => 0.0000
        [6] => 4999.0000
        [7] => 19.7500
    )

[6] => Array
    (
    )

If I try to add ?: in the line break group it still do it. Can anyone help me, I am stuck there. Thanks.

  • 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-06-08T16:05:51+00:00Added an answer on June 8, 2026 at 4:05 pm

    Not knowing any particulars of php matching, I’ll take your word that the regex is working like you show it is (using my preferred regex I’m not capturing in the same way).

    I’ll assume you are trying to remove those blank matches. I’ll also believe that those “newlines” are actually encoded into the input, and not left as literal \‘s and \r‘s and \n‘s.

    The problem seems to be the “newlines” are being matched twice? Like you match just the \n on one pass, and then the \r on the next pass?

    The simplest solution would be to restrict the newline to be the type you know the file has: /([^\"]|\"[^\"]*\")*?(\n\r)/
    Does this help?

    Alternatively, I would just use a regex split (delimited by comma) on each line of input.

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

Sidebar

Related Questions

Before I start, I should let you know that I'm hardly experienced in PHP.
Before I start, I know there is this post and it doesn't answer my
Before I start know this: I am extremely new to Java and programming. How
before I start I want to point out that I tagged this question as
     Before we start I know a fair few people consider tests that hit the
Before I start I should say I know this seems like a long shot,
Before I start the question, I know that some of you won't read the
Let me start by saying that I know there are a few topics discussing
Before i start, i know the MD5 is compromised (collision attack and speed of
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran

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.