@@ -43,30 +43,22 @@ function remove_utf8_bom($text) {
4343 * Converts csv data into a data structure. The returned value is an array
4444 * with each element representing a row of the csv. Each element is an array
4545 * with column names as keys and fields as values.
46- *
4746 * @param $csv_data The data.
4847 * @param $row_terminate The character represening a new row.
4948 * @param $field_terminate The character representing the end of a field.
5049 * @param $field_quote The character used to quote fields.
5150 * @param $field_escape The character used to escape special characters in the field content.
52- *
5351 * @return The data structure corresponding to the csv data.
5452 */
5553function csv_parse ($ content , $ row_terminate = "\n" , $ field_terminate = ", " , $ field_quote = '" ' , $ field_escape = "\\" ) {
56-
5754 $ content = trim (csv_normalize ($ content )) . "\n" ;
58-
5955 $ result = array ();
6056 $ header = array ();
6157 $ row = array ();
62-
6358 $ field = '' ;
6459 $ is_quoted = false ;
65-
6660 $ in_body = false ;
67-
6861 $ field_index = 0 ;
69-
7062 $ index = 0 ;
7163 $ length = strlen ($ content );
7264 while ($ index < $ length ) {
@@ -112,10 +104,7 @@ function csv_parse ($content, $row_terminate = "\n", $field_terminate = ",", $fi
112104 $ field = '' ;
113105 $ is_quoted = false ;
114106 $ field_index ++;
115- } else if (
116- ($ char == $ row_terminate && !$ is_quoted )
117- || $ index === $ length - 1 )
118- {
107+ } else if (($ char == $ row_terminate && !$ is_quoted ) || $ index === $ length - 1 ) {
119108 // End field or header
120109 if ($ in_body ) {
121110 // Body
@@ -126,7 +115,6 @@ function csv_parse ($content, $row_terminate = "\n", $field_terminate = ",", $fi
126115 }
127116 $ field = '' ;
128117 $ is_quoted = false ;
129-
130118 // End row
131119 $ field_index = 0 ;
132120 if ($ in_body ) {
@@ -143,6 +131,5 @@ function csv_parse ($content, $row_terminate = "\n", $field_terminate = ",", $fi
143131 }
144132 $ index ++;
145133 }
146-
147134 return $ result ;
148- }
135+ }
0 commit comments