This is the Message Centre for R'win
- 1
- 2
A1021645 - PHP/Random bgcolor
OwlofDoom Started conversation Apr 15, 2003
A1021645
Hi there R'Win...
I've been assigned to sub-edit your entry on PHP/bgcolor. It makes an interesting read, but I can't help but think this is all a little PHP3. Have you heard of the array_rand() function?
Here's how I'd do it...
<?php
$colours = array('#ffffff','#bbbbbb','#800080');
$bgcolour = $colours[array_rand($colours)];
echo "\n";
?>
...
That's for your benefit, mind. I'll wait for your approval to update the entry.
~
A1021645 - PHP/Random bgcolor
R'win Posted Apr 16, 2003
I have heard of that function. The original random script is the first array-less one. The array was an idea I had while writing the entry and at the time I hadn't really used arrays that much; now I've discovered how versatile and useful they can be.
Now, that is probably they way I would do it, too. Feel free to change it.
A1021645 - PHP/Random bgcolor
OwlofDoom Posted Apr 16, 2003
I think I'd rather add it, and change the way you've defined your arrays... there's no need to do a count in that C-style, as PHP has a (iirc) count($array) function to do it for you.
I can be your PHP guru if you like. Take a look at http://owlsound.co.uk/me/ which was all written in that wonderfully system-hogging language.
~
A1021645 - PHP/Random bgcolor
R'win Posted Apr 16, 2003
> I think I'd rather add it, and change the way you've defined your arrays
That's what I said (or at least that's what I meant). I agree entirely; now that I know more about arrays I see that that is a much better way of doing things and would do it like that myself has I done the entry now instead of back then.
> PHP has a (iirc) count($array) function
yes, it does; I've used it
> I can be your PHP guru if you like
No thanks; I believe I'm enough of a 'guru' (in knowldge if not age and beard length ) to manage on my own
> which was all written in that wonderfully system-hogging language.
If you mean PHP, then http://richardwinskill.co.uk is similarly powered (I can assure you there is no javascript anywhere) and http://galsing.richardwinskill.co.uk is the most powerful and versitile PHP script I've ever written, if i do say so myself...
A1021645 - PHP/Random bgcolor
OwlofDoom Posted Apr 17, 2003
Excellent stuff, sir!
I didn't mean any offence by offering my services. I've moved onto better climes since my PHP days (I'm a python man now, but I suspect that'll change in time).
I was a little surprised that you knew the ${$string}} trick for introspective variable reference and didn't know about arrays, mind. I couldn't live without my arrays (well, more specifically, lists and hashes/dictionaries - which is what PHP arrays really are)!
http://owlsound.co.uk/me/mm.php is my crowning achievement in PHP but I won't dare show you the source code as it's a complete nightmare. I suppose I should get round to writing a nice clean OO Python version of it sometime (note what I'm the Keeper of ... ).
~
A1021645 - PHP/Random bgcolor
OwlofDoom Posted Apr 17, 2003
Excellent stuff, sir!
I didn't mean any offence by offering my services. I've moved onto better climes since my PHP days (I'm a python man now, but I suspect that'll change in time).
I was a little surprised that you knew the ${$string}} trick for introspective variable reference and didn't know about arrays, mind. I couldn't live without my arrays (well, more specifically, lists and hashes/dictionaries - which is what PHP arrays really are)!
http://owlsound.co.uk/me/mm.php is my crowning achievement in PHP but I won't dare show you the source code as it's a complete nightmare. I suppose I should get round to writing a nice clean OO Python version of it sometime (note what I'm the Keeper of ... ).
~
A1021645 - PHP/Random bgcolor
R'win Posted Apr 18, 2003
I did know a bit about arrays, I just hadn't come across the array_rand() function at the time
I've done a bit of Python, but nothing really advanced; the most I've done is a small text-based adventure game and a simple Asteroids game
I like the mastermind script
A1021645 - PHP/Random bgcolor
OwlofDoom Posted Apr 19, 2003
array_rand() is actually a really simple PHP function to write:
function array_rand($array) {
return rand(count($array));
}
... mind you, that only works for numerical arrays, like the one in the example... the real array_rand() can return keys for hashed arrays too...
~
A1021645 - PHP/Random bgcolor
R'win Posted Apr 19, 2003
I know about array_rand() *now*; I've used it a fair bit. I just hadn't met it *then*
A1021645 - PHP/Random bgcolor
OwlofDoom Posted Apr 20, 2003
Blimey! Is this entry old, or are you just picking up PHP fast? I learned about array_rand() late too as my book (PHP4 Bible) does appear to leave it out altogether...
~
A1021645 - PHP/Random bgcolor
R'win Posted Apr 20, 2003
Well, both really. The entry was created on Dec 5th 2002 so it's a good few months old, and I pick up the odd function here and there; mainly from the PHP documentation at http://www.php.net.
A1021645 - PHP/Random bgcolor
OwlofDoom Posted May 15, 2003
Do you mind if I change your awfully complicated while() loop for something more useful in your article?
I think the following:
$colours = array(
"#ffffff",
"#ffff99",
"#00ccff",
"#66ff99",
"#ffcc00",
"#d7ebff",
"#ccffcc"
);
is better than your:
$c1 = "#ffffff";
$c2 = "#ffff99";
$c3 = "#00ccff";
$c4 = "#66ff99";
$c5 = "#ffcc00";
$c6 = "#d7ebff";
$c7 = "#ccffcc";
$colours = array();
$n=1;
while(isset(${"c$n"})){
$colours[] = ${"c$n"};
$n++;
}
but I won't change it if you'd not like me to.
~
PS I'm sorry about being so late here, I got tied up with project work and I've only just been freed from the cage!
A1021645 - PHP/Random bgcolor
R'win Posted May 15, 2003
Feel free.
Now that I've had more experience of PHP I know that's better and I would do it that way myself were I to re-do the entry
A1021645 - PHP/Random bgcolor
OwlofDoom Posted May 15, 2003
Well, I don't want the entry to celebrate its anniversary before going into the EG!
A1021645 - PHP/Random bgcolor
R'win Posted May 17, 2003
There should be a " work that slowly" after "Do you"...
Key: Complain about this post
- 1
- 2
A1021645 - PHP/Random bgcolor
- 1: OwlofDoom (Apr 15, 2003)
- 2: R'win (Apr 16, 2003)
- 3: OwlofDoom (Apr 16, 2003)
- 4: R'win (Apr 16, 2003)
- 5: OwlofDoom (Apr 17, 2003)
- 6: OwlofDoom (Apr 17, 2003)
- 7: R'win (Apr 18, 2003)
- 8: OwlofDoom (Apr 19, 2003)
- 9: R'win (Apr 19, 2003)
- 10: OwlofDoom (Apr 20, 2003)
- 11: R'win (Apr 20, 2003)
- 12: OwlofDoom (May 15, 2003)
- 13: R'win (May 15, 2003)
- 14: OwlofDoom (May 15, 2003)
- 15: R'win (May 15, 2003)
- 16: OwlofDoom (May 15, 2003)
- 17: R'win (May 15, 2003)
- 18: OwlofDoom (May 15, 2003)
- 19: R'win (May 17, 2003)
- 20: R'win (May 17, 2003)
More Conversations for R'win
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."