What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Some PHP Help

Some PHP Help
Author: Message:
Ash_
Senior Member
****

Avatar

Posts: 638
Reputation: 31
35 / Male / –
Joined: Aug 2004
RE: Some PHP Help
quote:
Originally posted by ValSpy
quote:
Originally posted by Ash_
use scan dir to scan for all gif files. (scandir and substr). then load them all into an array get a random namber thats not bigger then count($array); and use that image.

www.php.bet to look up those two functions =)
www.php.bet? i think its .net anyways i have no clue what you just said after all im a total php newbie


lol, you aint gonna learn if i give you the code are you?

code:
<?php
$dir    = '/tmp';
$files1 = scandir($dir);

print_r($files1);
?>

that code gets and displays all contents of a folder.

code:
echo substr('abcdef', -1, 1); // f

prints f.

so you could go.

code:
$dir    = '/images';
$files1 = scandir($dir);

for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}


now all the images in the folder are in the $images array.

now we get a random number.

code:
$num = rand(0, count($files1));

all code.

code:
$dir    = '/images';
$files1 = scandir($dir);

for ($x=0;$x<count($files1);$x++){
if (substr($files1[$x], -1, 3) == 'jpg') {
$images[] = $files1[$x];
print_r ($images);
}
}
$num = rand(0, count($files1));
echo "<img src='$dir/$images[$num]' />


its not the cleanest way to write it but i should work (not at home at the moment)
[/code]
[Image: jeansiger5.jpg]
11-25-2005 04:07 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Some PHP Help - by Val on 11-25-2005 at 03:49 AM
RE: Some PHP Help - by Ash_ on 11-25-2005 at 03:52 AM
RE: Some PHP Help - by Val on 11-25-2005 at 03:56 AM
RE: Some PHP Help - by Ash_ on 11-25-2005 at 04:07 AM
RE: Some PHP Help - by Val on 11-25-2005 at 04:14 AM
RE: Some PHP Help - by Ash_ on 11-25-2005 at 04:15 AM
RE: Some PHP Help - by Val on 11-25-2005 at 04:24 AM
RE: Some PHP Help - by Ash_ on 11-25-2005 at 04:27 AM
RE: Some PHP Help - by Val on 11-25-2005 at 04:35 AM
RE: Some PHP Help - by Mike on 11-25-2005 at 12:57 PM
RE: Some PHP Help - by -dt- on 11-25-2005 at 02:17 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On