减少代码中重复的HTML输出

时间:2014-10-13 05:13:15

标签: php

如何减少以下代码?



<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'>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

我不是100%肯定你在问什么,但如果你正在硬编码,你可以为更好的代码做一个循环:

<?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 } ?>