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
https://forums.phpfreaks.com/topic/151274-preg_split-dies-without-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.