banner
「云华」CloudSino

网络一隅¦Net`Corner

愿我的祝福与你同在︕
github
bilibili
zhihu
steam
discord user
misskey
follow
email

Component for inserting Chairman Mao's quotations on the webpage

Inspired by Yiyan API, Ancient Poetry API, and Daily Bible
Using a reprint from 1966 found online, this version should be safe
The source file is TXT, formatted with a script, currently totaling 432 entries
PHP and data files have been uploaded to Github, feel free to use


  1. Create a file named api.php in the website directory, with the content
<?php
// File to store data
$filename = 'yulu.dat';        
 
// Specify page encoding
header('Content-type: text/html; charset=utf-8');
 
if(!file_exists($filename)) {
    die($filename . ' data file does not exist');
}
 
// Read the entire data file
$data = file_get_contents($filename);
 
// Split into an array by newline
$data = explode(PHP_EOL, $data);
 
// Randomly get a line index
$result = $data[array_rand($data)];
 
// Remove extra newline characters (for safety)
$result = str_replace(array("\r","\n","\r\n"), '', $result);
 
echo 'document.write("'.htmlspecialchars($result).'");';
  1. Upload the yulu.dat data file in the same directory (see above)

  2. Call this code where you need to insert it

<script src="http://yourdomain/api.php"></script>

Referenced: Simple Implementation of Yiyan / Random Sentence Function in PHP | Meng Kun Blog

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.