banner
「云华」CloudSino

网络一隅/Net`Corner

愿我的祝福与你同在!
bilibili
steam
github
zhihu
misskey
email

Component for inserting Chairman Mao's quotes on web pages

Inspiration comes from Hitokoto API, Ancient Poetry API, and Daily Bible
Used a reissue from 1966 found online, this version should be safe
The source file is TXT, the format was organized using a script, currently a total of 432 entries
PHP and data files are uploaded to Github, feel free to use


  1. Create a file api.php in the website directory with the following 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 line breaks
$data = explode(PHP_EOL, $data);

// Get a random line index
$result = $data[array_rand($data)];

// Remove extra line breaks (just in case)
$result = str_replace(array("\r","\n","\r\n"), '', $result);

echo 'document.write("'.htmlspecialchars($result).'");';
  1. Upload the data file yulu.dat in the same directory (see above)

  2. Call this code where you need to insert it

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

Reference: PHP Simple Implementation of Hitokoto / Random Sentence Function | Mengkun Blog

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