Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2009
    Location
    Pennsylvania, United States
    Posts
    54
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Exclamation PHP split CSV line, regex

    I'm trying to read data from a CSV, and need to know a regular expression to split the line:

    Here's what I have so far, but it doesn't work:

    PHP Code:
    $pattern '/(,(?: ))/';
    $line preg_split($pattern$data); 
    please do NOT tell me about fgetcsv(), I'm aware of that, but I think using a regex would be easier.

    Any suggestions?

    Thanks!

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Why make things more difficult and less efficient? Is there a reason you're avoiding fgetcsv()?

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I think regexp for CSV is to complex. Reason: you can use TAB or ,; as
    delimiter. I think the escape character and look ahead for the
    closing " or ' will kill you. Mainly the parsing of the CSV will
    bee very slow.

    I use dbTube.org and the native excel format xls. The tool did have
    a UI like iTunes. But the source code is included. In this case you can
    customize or integrate them seamless in your app.

    Greetings


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •