Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Last active November 29, 2023 14:39
Show Gist options
  • Save adeel-raza/613bb8cb9664b55de7a2a845b2e62c5d to your computer and use it in GitHub Desktop.
Save adeel-raza/613bb8cb9664b55de7a2a845b2e62c5d to your computer and use it in GitHub Desktop.
Random Quote generator using api.quotable.io in PHP
<?php
function get_random_quotes() {
$api_url = 'https://api.quotable.io/random';
$response = @file_get_contents( $api_url );
$error = error_get_last();
if ( $error ) {
echo 'no quotes available at the moment';
} else {
$quotes_output = json_decode( $response, true );
if ( isset( $quotes_output['content'], $quotes_output['author'] ) ) {
return $quotes_output['content'] . '<br>' . $quotes_output['author'];
} else {
echo 'no quotes available at the moment';
}
}
}
$display_quote = get_random_quotes();
?>
<strong> <?php echo $display_quote; ?> </strong>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment