Home > Backend Development > PHP Tutorial > PHP function that randomly outputs famous quotes

PHP function that randomly outputs famous quotes

WBOY
Release: 2016-07-25 09:03:28
Original
1110 people have browsed it
  1. function random_str () {
  2. $poems="The value of life is not measured by time, but by depth. - Leo Tolstoy
  3. Threesome, There must be a teacher. Choose what is good and follow it, and change what is bad. ——Confucius Life is not a pleasure, but a very heavy work. —— Leo Tolstoy. To become synonymous with excellence, many people do not need an environment of outstanding quality. —— Steve Jobs
  4. Is there any other reason to live to change the world? —— Steve Jobs
  5. Follow yourself. —— Steve Jobs.
  6. Life is unfair; you have to adapt to it. ——Bill Gates
  7. Remind yourself to pay attention to happiness, just like looking at the sun on a cold day, your heart will be warm and bright without knowing it. ——Bi Shumin.
  8. Happiness is a vibration of the soul. It is like an ear that can listen to music. It needs constant training - Bi Shumin
  9. The world does not care about your self-esteem before you feel good about yourself. Achieve something. ——Bill Gates
  10. Life is empty and boring only to boring people - Chernyshevsky";
  11. $poems=explode("n",$poems) ;
  12. return $poems[rand(0,count($poems)-1)];
  13. }
  14. function says(){
  15. $says=random_str();
  16. echo $says;
  17. }
  18. ?>
Copy code
Key statements: $poems=explode("n",$poems); return $poems[rand(0,count($poems)-1)];

If you are using wordpress, you can put the file says.php in the theme root directory, then modify header.php in the theme root directory and insert a statement in front:

Copy the code
and insert the following statement where you want to display random famous quotes: says(); This way it can be called.

Of course, it can also be used in any other PHP program to achieve colorful display functions.

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