Jump to content

preg_split dies without error


ryan_z

Recommended Posts

Hello, on the PHP site I found some code to turn a CSV file into an array like so.

 

1,dog,cat,mouse

2,fish,shark,squid

 

[0] => Array
        (
            [0] => 1
            [1] => dog
            [2] => cat
            [3] => mouse
        )
[1] => Array
        (
            [0] => 2
            [1] => fish
            [2] => shark
            [3] => squid
         )

 

Anyway, my csv file is about 500-5000 lines and each row has 33 columns.  The function I was using had this code that was failing:

$expr="/\n(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/";
$rows=preg_split($expr,trim($fileContent));

This worked fine if I had a file with 133 or less rows. Once I went over 133 rows the script immediately failed (no 30 second wait or anything). The script would not even print text outside of the php brackets.  Just a blank page. I'm not too good with regular expressions, so I was having trouble working with it, thank you in advance.

 

I'm using PHP 5.2.8 and Apache 2.2.11 on FreeBSD 6-4

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.