You are here: Re: sorting random values from a string « PHP Programming Language « IT news, forums, messages
Re: sorting random values from a string

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация