One interview question, thinking, and code. A semicolon data file with a high score is shown as follows: each STRING is a random STRING with an unknown length. each line has multiple strings, and the number and position are unknown. What conditions must be met for the data file to parse the x string of the nth row using PHP? if the setting meets these conditions, write the Parsing method or idea. STRING;... ST: a quiz question. evaluate your ideas and code. High Score
There is a semicolon separated data file as follows:
Each STRING is a random STRING with an unknown length. each line has multiple strings and the number and position is unknown.
What conditions must be met for the data file to parse the x string of the nth row using PHP? if the setting meets these conditions, write the Parsing method or idea.
STRING ;......
STRING ;......
STRING ;......
------ Solution --------------------
Implement functions without considering other orders
Directly use the file () function to read each row of the file. each row is a unit of the array, and N rows are the keys of the array. then, the row is split to X.
------ Solution --------------------
Function get_str ($ len, $ location)
{
$ Content = file_get_contents('str.txt ');
$ Str_arr = explode ("\ n", $ content );
Foreach ($ str_arr AS $ key => $ val)
$ Str_arr [$ key] [] = explode (';', $ val );
Return (isset ($ str_arr [$ len] [$ location])? $ Str_arr [$ len] [$ location]: false;
}
No problem.
------ Solution --------------------
Haha .. All are guesses.
The above test, so it is good = _ =.
$ Str_arr [$ key] [] = explode (';', $ val); delete