The smartest way to generate duplicate HTML source code. Using PHP?
P粉146080556
P粉146080556 2023-09-10 16:37:09
0
1
618

Hi, I would like to know what is the sensible way to generate duplicate HTML source code (shown below). Let's say I have 30 rows numbered from 1 to 30. I have a lot of pages like this that need this structure. I've used a PHP loop to generate this code in the page itself, since I'm using PHP in my project anyway.

My question is, is this a wise approach? What is the best practice in this situation? I'm not sure it's wise to use PHP to generate HTML every time in a page. Or is it?

Thank you for your guidance or suggestions.

<a href="images/mypic (1).jpg">
<img src="images/mypic (1).jpg" alt="Picture 1">
</a>

<a href="images/mypic (2).jpg">
<img src="images/mypic (2).jpg" alt="Picture 2">
</a>

etc..

P粉146080556
P粉146080556

reply all(1)
P粉014293738

This is exactly what PHP is for: generating HTML code.

You can use a simple for loop:

<?php for($i=1; $i<=30; $i++) : ?>
  <a href="images/mypic (<?= $i ?>).jpg">
    <img src="images/mypic (<?= $i ?>).jpg" alt="Picture <?= $i ?>">
  </a>
<?php endif; ?>

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template