Use javascript+php to randomly display pictures _php tutorials

Source: Internet
Author: User
Presumably you'll be using JavaScript to randomly display pictures. But what if a picture's data (such as a link) changes frequently or is modified or added by the user? I have a solution here.
Put the picture information (such as name, address, link, etc.) in a TXT file (if MySQL is better, no matter). The PHP program is called by JavaScript in the HTML file, and the PHP program reads the image data randomly. See the procedure below:
Suppose there are TP.TXT content as follows: (each field represents ' Picture name ', ' Link Location ', ' Picture position ', tab 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 is actually generating a JavaScript language)
$arrayall =file ("Tp.txt"); Read tp.txt content into an array
$arrays =count ($arrayall);
if ($arrays ==1) {//because rand (0,0) is wrong
$selectrand = 0;
}else{
Srand (Double) microtime () *1000000);//set random number Seed
$selectrand =rand (0, $arrays-1);
}
$exstr =explode (Chr (9), $arrayall [$selectrand]);//randomly remove one from all and split
?>
document.write (' target= ' "new" > "width=" "height=" "alt=" ">");
HTML file





(You can put the scripty in the position you need, and you can add the settimeout () function to make a timed refresh)

http://www.bkjia.com/PHPjc/445151.html www.bkjia.com true http://www.bkjia.com/PHPjc/445151.html techarticle presumably you'll be using JavaScript to randomly display pictures. But what if a picture's data (such as a link) changes frequently or is modified or added by the user? I have a solution here. Put the picture ...

  • Related Article

    Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.