Random | Show presumably you'll use JavaScript to randomly display pictures. But what if the information of the picture (such as links) is constantly changing, or modified and added by the user? I have a way here.
Put the picture information (such as name, address, link, etc.) in a TXT file (if there is better MySQL, no). HTML file in the JavaScript call PHP program, PHP program randomly read picture data. procedure See below:
Suppose there are TP.TXT contents as follows: (each field represents ' Picture name ', ' link position ', ' picture position ', and between fields for tab)
OSO www.oso.com.cn Www.oso.com.cn/image/logo.gif
163 www.163.com Image.163.com/images/logo.gif
Sohu www.sohu.com Www.sohu.com/image/logo.gif
Readrand.php (this program is actually generating a JavaScript language)
?
$arrayall =file ("Tp.txt"); read out tp.txt content to array
$arrays =count ($arrayall);
if ($arrays ==1) {//because rand (0,0) is wrong
$selectrand = 0;
}else{
Srand ((double) Microtime () *1000000);/set random number of seeds
$selectrand =rand (0, $arrays-1);
}
$exstr =explode (Chr (9), $arrayall [$selectrand])//randomly remove one and split from all
?>
document.write (' <a href= "; echo $exstr [1];? > "target=" new "> "width=" "height=" "alt=" echo $exstr [0];? > "></a>");
HTML file
<body>
<script language= ' javascript ' src= ' readrand.php ' >
</script>
</body>
(You can put scripty in the position you need, and you can add settimeout () function to achieve timed refresh)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.