Home > Backend Development > PHP Problem > How to express random background image in php

How to express random background image in php

Release: 2023-02-27 19:38:01
Original
3476 people have browsed it

How to express random background image in php

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(&#39;Content-Type: text/html; charset=UTF-8&#39;); 
$img_array = glob("./img/*.jpg",GLOB_BRACE); 
$img = array_rand($img_array); 
header("location:.$img_array[$img]"); 
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template