I'd like to ask you some thoughts on the questions of today's php interview.

the written questions for today"s php interview do not have a lot of experience in data processing. I look confused. I would like to ask you some ideas on these questions

.

clipboard.png

question 1: filter out the records in the 5 million data that contain "test" in the memo field and save them in the: output.txt file.
question 2: the first 100000 pieces of data are formatted, and the suffix is output as ID.jpg:1, http://www.test.com/1.jpg. Test data 1 is saved in output2.txt

.
Php
Jan.13,2022

read line by line + regular extract or replace

What's wrong with

?


  1. awk'/ Test / 'demo.txt > > output.txt
    grep' Test 'demo.txt > > output.txt
  2. this is not very [embarrassing]

the subject may want to pay attention to whether the interview focuses on code solving or other methods. If it is a code solution, you can refer to this article: https://codeshelper.com/a/11., which focuses on the reading of very large files by PHP. If you can do it in other ways, you can use awk coding to solve it.


give you the answer to the first question:

$f  = fopen('body.txt', 'r');
$f2 = fopen('output.txt', 'w');
while (!feof($f)) {
    $line = fgets($f);
    if (mb_stripos($line, '') !== false) {
        fwrite($f2, $line . "\n");
    }
}

the second question can be counted on the basis of the first question, to the end of 10W, each read a comma syncopation, parsing the second URL can.

if you can't answer such a simple question, the result of your interview will be worrying.

Menu