在我的地盤我有幾百行代碼的,就像這樣:PHP循環問題
<a href="highslide/images/large/08/02IMG_0012.jpg" class="highslide"
onclick="return hs.expand(this, config1)">
</a>
<a href="highslide/images/large/08/03IMG_0020.jpg" class="highslide"
onclick="return hs.expand(this, config1)">
</a>
<a href="highslide/images/large/08/04IMG_0019.jpg" class="highslide"
onclick="return hs.expand(this, config1)">
</a>
<a href="highslide/images/large/08/05IMG_0011.jpg" class="highslide"
onclick="return hs.expand(this, config1)">
</a>
我想知道,如果它可以使用PHP來拯救我有代碼的那麼多行。使用批量重命名器將照片文件名更改爲photo1.jpg,photo2.jpg等。我只是不確定如何實現PHP的原因,我是一個小菜鳥。我得到了這樣的somin到目前爲止:
$photo = 1;
$ext = .jpg;
while() {
echo '<a href="highslide/images/large/08/'.$photo.$ext.'" class="highslide" onclick="return hs.expand(this, config1)">';
$photo++
}
答案這裏是正確的,但有另一種方法:通過將圖像存儲在目錄中的內容循環。 (見:http://php.net/manual/en/function.readdir.php)。這種方法將阻止您每次上傳圖像時都必須編輯PHP文件,並且可以處理任意文件名。 – horatio 2011-04-08 15:45:10