duanli9930 2014-08-30 22:41
浏览 50
已采纳

PHP回显行X次不同的文本

Title might not make complete sense, couldn't think of a way to explain it so I will do a mock PHP example.

<?php
$startNumber = 1;
$endNumber = 15;
$fileExt = '.jpg';
?>

And then on the page it will echo from the $startNumber to the $endNumber in something like a foreach

<?php echo("<img src=\"#.jpg\">"); ?>

Hope this is making sense...

I'd also like to point out that the numbers < 10 start with a 0 so it will need to be in the image source link.

  • 写回答

1条回答 默认 最新

  • dongxun1978 2014-08-30 22:48
    关注

    echo is not a function, it's a language construct. Don't use ().

    Also you need to use a loop like for() to do that (Also see sidenote of Fred -ii).

    $endNumber = 15;
    for($i = 1; $i <= $endNumber; $i++) {
        if($i < 10) {
            $i = "0".$i;
        }
        echo "<img src=\"".$i.".jpg\" />";
    }
    

    If this is not what you asked, add more information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题