One interview question, thinking, and code. High score solution-php Tutorial

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.