php - How to edit the following script which grabs data from a text file? -


I want to do 2 things on my script below, in which I am currently struggling.

Information about the function: Currently it takes the last 20 lines and displays information based on the requested columns.

First) I want to ignore those lines, the same columns are 5 and 13. Example: (The two rows below should be ignored because the column in the first row corresponds to the 5 column 13 and the second row is similar to the first because the first name of column 5 corresponds to the name of the column 13)

  1,42,16, 201, Satkovrflo_ugr, 1, 6762160, 39799, 9817242, 6762160, 39884, 10010545, Satkovrflo_ugr, 2, 1351147, 1165, 483259, 1351147, 1115, 241 630, 0 1, 46,27, 201, [StackhouseFlo_User | stackoverflow_userother], 1, 4,078,465, 286,991, 1,594,830, 4,078,465, 287,036, 1,643,156, stackoverflow_user, 2, 1,357,147, 1115, 241,630, 1,357,147, 1065, 120,815, 0  

second) I want to include reserved words. Like the above, but I should specify the reserved word: Can say that the column is 5 or 13 or both in the name: stack , these lines should be ignored .

  1,42,16, 201, stack, 1, 6,762,160, 39,799, 9,817,242, 6,762,160, 39,884, 10,010,545, stackoverflow_usersecond, 2, 1,351,147, 1165, 483,259, 1,351,147, 1115, 241,630, 0 1, 46, 27, 201, [StackHowflower_Users | stackoverflow_userother], 1, 4,078,465, 286,991, 1,594,830, 4,078,465, 287,036, 1,643,156, stack 2, 1357147, 1115, 241630, 1357147, 1065, 120 815, 0 L,46,27, 201, [stack | stackoverflow_userother], 1, 4,078,465, 286,991, 1,594,830, 4,078,465, 287,036, 1,643,156, stacks, 2, 1,357,147, 1115, 241,630, 1,357,147, 1065, 120,815, 0  

All of the above Lines should be due to stack in 5th column or 13th or both.

This is my real work below:

  Function DMMRankings () {# A array reads a file in the $ rows = file (' C: /path/to/file.txt ', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); # Take the last 20 rows of a file - that is, the last 20 values ​​in the array $ last_ten = array_slice ($ rows, -20); # Create an array for output $ n = 1; $ Content = ''; Give foreign currency ($ last_ten $ l) {# values ​​as values ​​separated by commas $ arr = explosion (",", $ l); # If col 5 has multiple values, if first one takes preg_match ("/æ[(.+) \?? /", $ Arrivals [4], $ match)) {$ arrivals [4] = $ matches Is [1]; } #We want the data in an output array $ Data = array ( 'Rank-pause' = & gt; $ n ++, 'rank-name' = & gt; $ arr [4], 'rank-Dimughr' = & gt; $ arr [12]); $ Content = Template :: Load ('Ranking DM-'. ($ N% 2 == 1? 2: 1), $ data); } $ This- & gt; Content = Template :: Load ('user_rankingsdm', array ('ranking' => gt; $ content)); }  

Please help me how I can do this on my current function. Thanks!

The following stack questions will tell you the best way to read the last few lines of your file, I Have seen comments.

Regarding actual processing, it is CSV so that to create your array, see the following inbuilt PHP function:

once you have that sorted:

  / * this file * / $ aryCSV = array_map ( 'str_getcsv' only one-liner to parse) file ( 'data.csv ')); Foreach ($ aryCSV as $ aryRow) {/ * This is your "check ignore" * / if ($ aryRow [5] == 'stack' & amp; $ aryRow [13] == ' Stack ') {/ * Go to next trip / continue; } / * Is loading your template and saving data * /}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -