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.
#2

[eluser]John Fuller[/eluser]
...dolor sit amet!

Thanks dude. Wink
#3

[eluser]Lone[/eluser]
Nice work - I have always used Lipsum for heaps of demo content Smile
#4

[eluser]TheFuzzy0ne[/eluser]
I've just noticed a small error which I've now corrected. &start;parameter in the $url was hardcoded as "yes", I've changed this now, not that it should matter much. Big Grin

EDIT: Another error... Every time I save the edit, the backend keeps adding semi-colons, as if the parameters names were HTML entities. Does anyone know how to fix this?
#5

[eluser]Lone[/eluser]
The more I think about it the more I think that this might not be the best approach to achieve filling in content areas. From what I would imagine your own page will take a moment longer to load as it is waiting on the lipsum website - especially if your just working on a local development site.

Maybe the best approach is to just grab the whole lipsum content (from memory it shouldnt be &copyWink and rawly save it as a string (yes this will add extra bulk to your code but shouldn't be too much IMO) and then make the function parse the string as required?
#6

[eluser]TheFuzzy0ne[/eluser]
I had been thinking about doing that, and to be honest I had actually started work on my own random text generator, but I couldn't get my algorithm right and didn't want to spend too much time on it, so I decided to just get lipsum to generate it for me.

The time difference it takes for the page to load (for me, anyway), is negligible. Should I cache the last request in a text file, and if you want a fresh one generated, you can simply add TRUE as the last parameter?

I think there should be a cache file for each type, but then that might not work very well if the the $amount parameter changes. Also, how would it work if you wanted to request say, 60 bytes? The beauty of the code is that it's very simple. I'm not sure where to draw the line between simplicity and overkill.

Don't get me wrong, I'm not discarding your suggestion, I'm just not sure of what the longterm effect would be.

It would be fantastic if lipsum.com published their source code. Big Grin
#7

[eluser]Kevin Kietel[/eluser]
Nice work, TheFuzzy0ne!

I've just released a jQuery plugin based on your idea. This plugin generates Lorem Ipsum text by using javascript. So this can be included on any webpage, even when offline.
This is my first real jQuery plugin, so thanks for providing me with the inspiration! Wink

Greetz,

Kevin Kietel
#8

[eluser]TheFuzzy0ne[/eluser]
Great, I look forward to seeing it. I can't take any credit for the concept. I just wanted something that I could use from within CI which was quick and simple, so I pinched the idea from the CPAN module.
#9

[eluser]Unknown[/eluser]
Hey, Kevin.. are you going to include a link to your jQuery plugin?
#10

[eluser]Kevin Kietel[/eluser]
[quote author="Restless Native" date="1209571567"]Hey, Kevin.. are you going to include a link to your jQuery plugin?[/quote]

Oops.... I think the link got lost when adding my post...
here you go:

http://www.sanderkorvemaker.nl/jquery/jLorem.php




Theme © iAndrew 2016 - Forum software by © MyBB