Php randomly outputs the famous saying code. How is the function of this random celebrity famous saying realized? In fact, it is very simple. we only need a string variable. Here we put all the famous quotes to be displayed randomly, and then we use exp. how is this function implemented?
In fact, it is very simple. we only need a string variable. Here we put all the famous quotes to be randomly displayed, and then use the explode function to break them into arrays, and then use the rand random number to generate a value, output a sentence in this array.
Directly run the code:
Says. php
The code is as follows:
Function random_str (){
$ Poems = "The value of life is measured not by time, but by depth. -- Lev tolistes
For the threesome, you must have a teacher. From the good, and from the bad. -- Confucius
Life is not a pleasure, but a very heavy job. -- Lev tolistes
Being synonymous with excellence, many people do not need an environment of outstanding quality. -- Steve Jobs
Living is to change the world. Is there any other reason? -- Steve Jobs
Follow yourself. Follow your heart. -- Steve Jobs
Life is unfair; adapt to it. -- Bill Gates
I often remind myself to pay attention to happiness, just as I often look at the sun on cold days, and my heart is warm and bright. -- Bi Shumin
Happiness is a kind of trembling mind. Like listening to music, it requires constant training. -- Bi Shumin
This world does not care about your self-esteem. This world expects you to achieve something before you feel good about yourself. -- Bill Gates
Life is empty and tasteless only in the eyes of dull people. -- Che yevski ";
$ Poems = explode ("\ n", $ poems );
Return $ poems [rand (0, count ($ poems)-1)];
}
Function says (){
$ Says = random_str ();
Echo $ says;
}
?>
The key lies in the following:
The code is as follows:
$ Poems = explode ("\ n", $ poems );
Return $ poems [rand (0, count ($ poems)-1)];
If you are using the wordpress blog system, you can put the file says. php under the topic root directory, modify the header. php under the topic root directory, and insert a statement to the front:
The code is as follows:
Then insert the following statement at the location where you want to display the random quotes:
Says ();
In this way, you can call it. I am not very familiar with the wordpress system. this method is definitely not the best.
Why? In fact, it is very simple. you only need a string variable. Here we put all the famous quotes to be randomly displayed, and then use exp...