0

ページロード時に対応するサイトにリンクされたランダムな画像を呼び出すスクリプトを探しています。これを行うためのjavascriptまたはphpの方法を知っている人はいますか?

4

1 に答える 1

1
<?php

$random = array(
  array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
  array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
  array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
  array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);

$current = rand(0, count($random) - 1);
print "<a href=\"" . $random[$current]['url'] . "\"><img src=\"" . $random[$current]['image'] . "\" alt=\"\" /></a>\n";

?>

早くて簡単。それを行うための最良の方法ではないかもしれません-私はそれを静的配列の代わりにデータベースに個人的にフックします-しかしそれはあなたを数秒で稼働させるでしょう。

于 2008-10-23T16:48:36.803 に答える