Home > All, PHP, Web > Simple PHP one-liner to generate random Lorem Ipsum (Lipsum) text.

Simple PHP one-liner to generate random Lorem Ipsum (Lipsum) text.

Copying and pasting lipsum text from a site such as lipsum.com can be boring and tedious at times, especially when you would like to test multiple blocks and how well they will look with text of varying length.

Getting random lipsum of varying length is pretty easy in PHP, in fact you can do it on just one line of code:

$lipsum = simplexml_load_file(‘http://www.lipsum.com/feed/xml?amount=1&what=paras&start=0′)->lipsum;

Need more than one random string? Turn it into a method:

function random_lipsum($amount = 1, $what = ‘paras’, $start = 0) {

return simplexml_load_file(“http://www.lipsum.com/feed/xml?amount=$amount&what=$what&start=$start”)->lipsum;

}

Where:

  • $amount is… how much of $what you want.
  • $what is either paras, words, bytes or lists.
  • $start is whether or not to start the result with ‘Lorem ipsum dolor sit amet…

Categories: All, PHP, Web