Skip to content
displays a random quote and author from a JSON file
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
base update quotes Feb 11, 2020
.gitattributes
.gitignore update quotes Jul 7, 2019
LICENSE Initial commit Sep 15, 2018
README.md Update README.md Mar 3, 2019
index.php lang ignore case Oct 9, 2018

README.md

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

You can’t perform that action at this time.