PHP code example of justpush-io / php-jokeapi

1. Go to this page and download the library: Download justpush-io/php-jokeapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

justpush-io / php-jokeapi example snippets




okeAPI\JokeClient;
use JokeAPI\JokeConstants;

// Create a new JokeClient
$client = new JokeClient();

// Get a random joke
$joke = $client->fetch();

// Print the joke
if ($joke['type'] === 'single') {
    echo $joke['joke'];
} else {
    echo "Setup: " . $joke['setup'] . "\n";
    echo "Delivery: " . $joke['delivery'];
}

$client->categories([
    JokeConstants::CATEGORY_PROGRAMMING,
    JokeConstants::CATEGORY_MISC
]);

$client->blacklist([
    JokeConstants::FLAG_NSFW,
    JokeConstants::FLAG_RELIGIOUS
]);

$client->format('xml');

$client->type(JokeConstants::TYPE_SINGLE);

$client->search('programmer');

$client->id(42);

$client->language(JokeConstants::LANG_GERMAN);

$client->safe();

$joke = $client->fetch();

$joke = $client
    ->categories([JokeConstants::CATEGORY_PROGRAMMING])
    ->blacklist([JokeConstants::FLAG_NSFW])
    ->safe()
    ->fetch();
bash
git clone https://github.com/yourusername/jokeapi-php.git