Typecho 随机一句/一言

samuel 2019-09-15 AM 58℃ 0条

有时想在某个地方随机显示一句话,这个代码就可以帮到你了。
把这句写进 functions.php

function random_str() {
        $poems = "I really want to talk to you, but I feel like I’m annoying you.
                  Your life is a result of the choices you make… if you don’t like your life it is time to start making better choices. 
                 ";
        $poems = explode("\n", $poems);
        return $poems[rand(0, count($poems) - 1)];
    }
    function says() {
        $says = random_str();
        echo $says;
    }
$poems = "第一句
          第二句
          第三句

上边是需要加入随机的话,回车结束一句。

在需要的地方调用就可以。

<?php says();?>
标签: 随机一句, 一言

评论啦~