We can put the background image into a folder, use the glob() function in PHP to return the folder where the image is located, and then use the rand() function to randomly call the folder in the folder. Picture, just set the called picture as the background picture.
Recommended: php server
Randomly generate background image PHP code:
<?php /** * PHP随机图显示 */ header('Content-Type: text/html; charset=UTF-8'); $img_array = glob("./img/*.jpg",GLOB_BRACE); $img = array_rand($img_array); header("location:.$img_array[$img]"); ?>
The above is the detailed content of How to express random background image in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
