Welcome Guest, Not a member yet? Register   Sign In
Ipsum Lorem
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone.

Here's a simple helper function I made, that I thought might help others. It simply fetches some random "ipsum lorem" text, to use to fill your pages when you are testing.


It would be useful to find this in the core at some point. It saves a lot of copying and pasting.

Code:
function ipsum_gen($amount=5, $what="paras", $start="yes")
{
    $url = 'http://www.lipsum.com/feed/html?amount=$amount&what;=$what&start;=$start';
    $handle = fopen($url, 'r');
    $html = stream_get_contents($handle);
    $pattern = '/\<div id=\"lipsum\">(.*)<\/div/Uis';
    preg_match($pattern, $html, $matches);

    return $matches[1];
}

EDIT: The above code contains two unintended semi-colons(;) in the $url string. If you intend to use this code, please remove them.

Parameters:

$amount = The amount of data you want to get (integer value)
$what = what kind of data ("list"/"paras"/"words"/"bytes")
$start = Whether or not it should start with "Ipsum Lorem" ("yes"/"no")

I know it's nothing to get excited about, but if it helps just one person other than myself, then it's a job well done. The closest thing I could find like this was a CPAN perl extension, and it's a lot bigger.

If anyone has any suggestions about more features, or how to improve it, please let me know.


Messages In This Thread
Ipsum Lorem - by El Forum - 04-28-2008, 12:21 PM
Ipsum Lorem - by El Forum - 04-28-2008, 02:34 PM
Ipsum Lorem - by El Forum - 04-28-2008, 03:33 PM
Ipsum Lorem - by El Forum - 04-28-2008, 03:53 PM
Ipsum Lorem - by El Forum - 04-28-2008, 05:39 PM
Ipsum Lorem - by El Forum - 04-28-2008, 06:03 PM
Ipsum Lorem - by El Forum - 04-29-2008, 03:34 PM
Ipsum Lorem - by El Forum - 04-29-2008, 04:31 PM
Ipsum Lorem - by El Forum - 04-30-2008, 05:06 AM
Ipsum Lorem - by El Forum - 05-02-2008, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB