php parse file

Solutions on MaxInterview for php parse file by the best coders in the world

showing results for - "php parse file"
Miguel Ángel
23 Aug 2020
1$txt_file    = file_get_contents('path/to/file.txt');
2$rows        = explode("\n", $txt_file);
3array_shift($rows);
4
5foreach($rows as $row => $data)
6{
7    //get row data
8    $row_data = explode('^', $data);
9
10    $info[$row]['id']           = $row_data[0];
11    $info[$row]['name']         = $row_data[1];
12    $info[$row]['description']  = $row_data[2];
13    $info[$row]['images']       = $row_data[3];
14
15    //display data
16    echo 'Row ' . $row . ' ID: ' . $info[$row]['id'] . '<br />';
17    echo 'Row ' . $row . ' NAME: ' . $info[$row]['name'] . '<br />';
18    echo 'Row ' . $row . ' DESCRIPTION: ' . $info[$row]['description'] . '<br />';
19    echo 'Row ' . $row . ' IMAGES:<br />';
20
21    //display images
22    $row_images = explode(',', $info[$row]['images']);
23
24    foreach($row_images as $row_image)
25    {
26        echo ' - ' . $row_image . '<br />';
27    }
28
29    echo '<br />';
30}