<!DOCTYPE HTML> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <table> <tr> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>2</td> </tr> </table> </body> </html> 

For example, there is a stat.html file with a table in it. Is it possible to add php to the file, namely to the table after

  <tr> <td>2</td> <td>2</td> </tr> 

next tr? <tr> <td> 3 </ td> <td> 3 </ td> </ tr>


Oleg B, not bad =)

Unfortunately this is not a ride. In the task you need to generate a static html file. And update it every time.


There is a file in the table. For example, in the table data referring to links on the site. When a link is added to the site, you need to take this file, open and add more data to the end of the table, that is, 1 tr.


Many thanks, the issue is resolved.

2 answers 2

File need static?


before the </table> add for example <!-- Add here --> add <!-- Add here -->

So:

 <table> <tr> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>2</td> </tr> <!-- Add here --> </table> 

test1.php file

  • generate new rows in the variable $ newrows
  • Add to $ newrows <!-- Add here --> Note: $newrows .= '<!-- Add here -->';
  • Then work with the file:
  • $ file = 'stat.html'; // file location
  • $FileSourse = file_get_content($file); // all html file code
  • $FileSourse = str_replace('<!-- Add here -->',$newrows,$FileSourse); // Add new lines to the code by replacing <!-- Add here --> with new generated lines.
  • file_put_contents($file, $FileSourse); // overwrite the file with the new code

    Change the file extension to stat.php and paste as many as you like:

     <!DOCTYPE HTML> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <table> <?php for ($i=0; $i<10; $i++) { ?> <tr> <td><?php echo $i; ?></td> <td><?php echo $i; ?></td> </tr> <?php } ?> </table> </body> </html>