do not know if you have found the major sites on the banner ads, each time we visit these sites, will see different advertising icon, or if you refresh the page every time, these ads banner will continue to change the random replacement. To achieve this effect although the use of JavaScript can also be achieved (like the Tenkine station of the dynamic transformation of advertising banner is by invoking JavaScript to achieve), but if we use PHP, we can also combine the database to do a large amount of data, such as a daily problem such as the function. Crap, let's take a look at how PHP can be used to achieve banner dynamic replacement function.
echo "<a href=//gophp.heha.net/index.html><img alt= into the world of PHP border=0 src=http://www.163design.net/p/a/ $randval .gif></a> ";
?>
we can find that the implementation of the program is very simple: the main thing is to use the Srand initialization random number generator to generate random numbers, and then call the RAND function within the defined valid range to get one of the random values, the last display http://www.163design.net/p/a /$randval. gif pictures banner, i.e. 0.gif, 1.gif, 2.gif, 3.gif, or 4.gif. For the sake of understanding, I list the syntax and related instructions for the RAND function as follows:
Rand
syntax: int rand ([int min], [int Max]);
return value: Integer
function Type: mathematical Operation
Content Description: This function is used to obtain random values. If you do not specify the maximum and minimum range of random numbers, this function automatically takes a random number from 0 to Rand_max. If a parameter is specified for min and Max, a number is taken from the specified parameter. For example, Rand (38,49) obtains a random value from 38 to 49. Where the UNIX system contains the 49,WIN32 system does not contain 49. It is noteworthy that in order to maximize the random number of random numbers, it is best to use Srand () to set new random numbers each time before taking random numbers. In this example, the time factor is added when a new random number is produced with Srand (), and the random number is generated at one out of 10,000 random rate when executed
9.1 We change the Head.inc file to apply this simple banner dynamic replacement function, while also linking to their corresponding URLs for different ad banner.
of course, first we have to get ready to replace the Exchange banner icon, but also to our page header plus our own website logo (01dc.gif).
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.