Skip to content

popoway/php-random-quotes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-random-quotes

GitHub tag GitHub Release Date GitHub repo size in bytes GitHub commit activity the past week, 4 weeks, year license
Developed on PHP, php-random-quotes is a simple API for querying a quote randomly selected from a JSON quote pile.

Quick Links

Live Demo: php-random-quotes
Release Notes: Release Notes

Usage

The following parameters are available:

Parameter Value Comment Optional Default value
base URL Location of the quote pile in JSON format. This will override "lang" parameter. true base/en.json
lang i18n codes defined in RFC 3066 Specify the language of available quotes. true en
output See below: json/quote-only/double-hyphen/no-hyphen/single-hyphen Specify the language of available quotes. true single-hyphen
json JSON of a single quote as return value
quote-only Quote only as return value
double-hyphen Two adjacent hyphens between quote and author as return value
no-hyphen Only a space bar between quote and author as return value
single-hyphen One hyphen between quote and author as return value

Examples:

Execute:

curl https://php-random-quotes.app.popoway.cloud/index.php?base=base/en.json&output=json

Return:

{"Quote":"Rediscover the world.","Author":"popoway"}

Execute:

curl https://php-random-quotes.app.popoway.cloud/index.php?lang=zh-cn&output=no-hyphen

Return:

做菜的人一般吃菜很少。……从这点说起来,愿意做菜给别人吃的人是比较不自私的。 汪曾祺

AJAX

This API can be used to inject random quotes in a static web page.

Sample codes:

var quoteAPIurl = 'https://php-random-quotes.app.popoway.cloud/';

// function to fetch quotes
function fetchQuote(elemId, url) {
  fetch(url)
    .then(function(response) {
      return response.text();
    })
    .then(function(text) {
      var elem = document.getElementById(elemId);
      if (elem) elem.textContent = text;
    })
}

// fetch quotes
fetchQuote('ajaxQuotes', quoteAPIurl);
<p>Your content goes here</p>
<p>Below is a random quote:</p>
<span id="ajaxQuotes">quote will be injected here</span>

Status

Basic features should work, since it is rather stable.

Contributing

Give me inspiration on quotes, or help translate it.

License

MIT