Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-23-2010, 12:14 AM   PM User | #1
johnnnn
New Coder

 
Join Date: May 2009
Location: Pennsylvania, United States
Posts: 54
Thanks: 16
Thanked 0 Times in 0 Posts
johnnnn is an unknown quantity at this point
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!
johnnnn is offline   Reply With Quote
Old 04-23-2010, 01:05 AM   PM User | #2
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
Why make things more difficult and less efficient? Is there a reason you're avoiding fgetcsv()?
__________________
ZCE
kbluhm is offline   Reply With Quote
Old 05-20-2010, 05:52 PM   PM User | #3
Martin Kunz
New to the CF scene

 
Join Date: May 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Martin Kunz is an unknown quantity at this point
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
Martin Kunz is offline   Reply With Quote
Reply

Bookmarks

Tags
csv, php, regex, split

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:13 PM.


Advertisement
Log in to turn off these ads.