Quick function to display bacon ipsum filler text


I recently was setting up a new site for a client, and found myself copying and pasting filler text.. After a while, I decided to just write this function to use bacon ipsum’s API instead:

function get_bacon($p=4){
    $url = "http://baconipsum.com/api/?type=meat-and-filler&paragraphs=".$p;        
    $timeout = 5;
    $json = curl_exec($ch);
    $json = json_decode($json);
    foreach($json as $i){
        echo "<p>$i</p>";

To use this function, just call it like this:

<php get_bacon(1);  ?>

Replace the 1 with how ever many paragraphs you actually need.

Filed Under: Code

Roger Stringer spends most of his time solving problems for people, and otherwise occupying himself with being a dad, cooking, speaking, learning, writing, reading, and the overall pursuit of life. He lives in Penticton, BC.

Connect: Twitter |  Google+
This content is supported by readers like you.