|
Posted by Rik Wasmus on 09/06/07 15:38
On Thu, 06 Sep 2007 17:26:25 +0200, pt36 <key.alberto@gmail.com> wrote:
> Ok Rik
> thanks for your help, but please tell me why this work
> <?php
> $string =3D "uno.jpg due.jpg tre.gif quattro.gif cinque.jpg";
> $array =3D explode(' ', $string);
> shuffle($array);
> $string =3D implode(' ', $array);
> echo $string ;
> ?>
>
> and this not work
> <?php
> if ($handle =3D opendir('banner/')) {
> while (false !=3D=3D ($file =3D readdir($handle))) {
> if ($file !=3D "." && $file !=3D "..") {
> $file =3D $file . " ";
Because a file might have a space in it, and it might be a directory? It=
's =
quite nonsense to keep juggling between an array & a string.
=
<?php
if ($handle =3D opendir('banner/')) {
$files =3D array();
while (false !=3D=3D ($file =3D readdir($handle))) {
if (is_file($file)) $files[] =3D $file;
}
shuffle($files);
echo implode(' ',$files);
closedir($handle);
}
?>
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|