简体   繁体   中英

Reduce repetitive HTML output in my code

How can I reduce the following code?

 <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/1_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/2_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/3_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/4_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/5_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/6_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/7_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/8_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/9_<?php echo $matches[1]; ?>.jpg'> <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/10_<?php echo $matches[1]; ?>.jpg'> 

I am not 100% sure what you are asking, but if you are hardcoding this, you can do a loop for nicer code:

<?php for($i = 1; $i <= 10; $i++) { ?>
    <img src='http://x1<?php echo $ranx ; ?>.ddff.com/t/<?php echo $cutstr ; ?>/<?php echo $i; ?>_<?php echo $matches[1]; ?>.jpg'>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM