Show pictures randomly with javascript + PHP _ PHP Tutorial
Source: Internet
Author: User
Use javascript + PHP to randomly display images. You will use javascript to randomly display images. But what if the image information (such as links) changes frequently or is modified or added by users? I have a solution here. You must use javascript to randomly display the image. But what if the image information (such as links) changes frequently or is modified or added by users? I have a solution here.
Put the image information (such as name, address, link, etc.) in a TXT file (if MYSQL is better, or not ). The PHP program is called by javascript in HTML files, and the PHP program randomly reads image data. For the program, see:
Assume that the content of TP. TXT is as follows: (each field represents 'image name', 'link location', and 'image location' respectively, and TAB is used between fields)
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 actually generates a javascript language)
$ Arrayall = file ("tp.txt" when reading the content of tp.txt to the array
$ Arrays = count ($ arrayall );
If ($ arrays = 1) {// because rand (0, 0) is wrong
$ Selectrand = 0;
} Else {
Srand (double) microtime () * 1000000); // sets the random seed.
$ Selectrand = rand (0, $ arrays-1 );
}
$ Exstr = explode (chr (9), $ arrayall [$ selectrand]); // randomly retrieve and divide all
?>
Document. write ('"target =" new ">" width = "200" height = "50" alt =" "> ');
HTML file
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service