Get random jokes with PHP using Joke API

A joke is a display of humor in which words are used within a specific and well-defined narrative structure to make people laugh and is usually not meant to be taken seriously. A joke is a short humorous piece of oral literature in which the funniness culminates in the final sentence, called the punchline.

In this article, we will be using Joke API to get random jokes.

Source Code :

<style type="text/css">
    background-color: aliceblue;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    border-radius: 15px;
    background-color: bisque;
    box-shadow:3px 10px 15px #abc;
    display: flex;
      align-items: center;
      text-align: center;
      font-size: 30px;
      padding: 50px;
      color: #555;
    	font-family: monospace;
    	font-weight: bold;
    	position: relative;
    position: absolute;
    top: 0;
    left: 0;
    font-size: 15px;
    background: #666;
    padding: 5px 10px;

  $api_url = "";
  $joke = json_decode(file_get_contents($api_url));

<div class="box-container">
  <div class="box">
    <div class="box-content">
      <div class="tag"><?php echo $joke->category;?></div>
      <?php if($joke->type=='single'){?>
        <span><?php echo $joke->joke;?></span>
      <?php } else {?>
        <div class="joke">
          <div class="setup">
            <?php echo $joke->setup;?>
          <div class="delivery">
            <?php echo $joke->delivery;?>
      <?php } ?>

Follow this video for complete guidance :


Recommended For You

About the Author: Ritesh Ghimire

Ritesh is a Computer Engineer, Web Developer and an active cricket follower.