I apologize for the beaten question .. But I still can not figure it out.

There is a txt file with a list of products, for example, with the following contents:

url-ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ | НазваниС | ОписаниС url-ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ | НазваниС | ОписаниС url-ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ | НазваниС | ОписаниС ...динамичСскоС количСство строк... 

QUESTION:

- What will the script for reading the txt file look like and display the data on the html page, where each line is displayed in a separate new div?

Approximate block diagram for one product:

 <div> <img src="URL"> <p id="Name"></p> <p id="Desсription"></p> </div> 

ps do not consider converting to another format (csv or json). And also plugins, because there I will have even more questions and problems (

Thank you all for participating. You make the world a better place.

  • What are your attempts on this thorny path? Why not use more suitable storage formats? - user207618 5:46 pm
  • txt is the easiest. excel - you will need a read plugin, csv - you need to draw it up. - Mesuti
  • And JSON ? ...... - user207618

1 answer 1

Option:

 $fh = fopen('filename.txt','r'); // Open file while ($line = fgets($fh)) { // Read line from file $tmp = explode("|", $line); // Get data from file ?> <!-------- html code --------> <div> <img src="<?= $tmp[0] ?>"> <!-------- ImageURL --------> <p><?= $tmp[1] ?></p> <!-------- Name --------> <p><?= $tmp[2] ?></p> <!-------- Description --------> </div> <!-------- html code ends --------> <?php } // while closing fclose($fh); // closing file handler ?> 

UPD:

 <style type="text/css"> .item{ display: inline-block } </style> <div class="main"> <?php $fh = fopen('filename.txt','r'); while ($line = fgets($fh)) { // <... Do your work with the line ...> // echo($line); $tmp = explode("|", $line); ?> <div class="item"> <img src="<?= $tmp[0] ?>"> <!-------- Image url --------> <p><?= $tmp[1] ?></p> <!-------- Name --------> <p><?= $tmp[2] ?></p> <!-------- Description --------> </div> <?php } fclose($fh); ?> </div> 
  • Those who interfere with HTML and PHP will be grilled at the same time in a pan and a cauldron. - user207618 pm
  • @Other possible if the pot is in a griddle. - Kosta B.
  • And all this in a steam bath! - user207618
  • The code is working! Tell me how to publish all this in html in separate div blocks? Now everything is made out entirely in one column - Mesuti
  • As an option, correct the item record to: <div class = "item"> | url pictures | Name | Description | </ div> - Mesuti