Home > Article > Web Front-end > Use javascript+php to randomly display images
Presumably you will use javascript to display images randomly. But what if the image information (such as a link) changes frequently, or is modified or added by the user? I have a solution here.
Put the image information (such as name, address, link, etc.) in a TXT file (MySQL is better, but it doesn’t matter). In the HTML file, Javascript calls the PHP program, and the PHP program randomly reads the image data. See the program$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 pick out a union from all Split
?>
document.write('');
HTML file
The above is the content of using javascript+php to randomly display images. For more related content, please pay attention to the PHP Chinese website (www.php.cn )!