You are here: Re: help - strings arrays and search.. « PHP « IT news, forums, messages
Re: help - strings arrays and search..

Posted by David Haynes on 01/09/06 02:47

oswald wrote:
> David Haynes <david.haynes2@sympatico.ca> napisal(a) w wiadomosci
> news:bGfwf.28780$Gt3.12768@fe24.usenetserver.com:
>
>> oswald wrote:
>>> ok.. here's the deal...
>>>
>>> I have an array of file names (read from directory). I'm having
>>> trouble working out something like this :
>>>
>>> user searches the files (array of filenames, say array1) for a
>>> specific name (filenames are something like "JOHN SMITH.jpg" - yes,
>>> they contain spaces and I can't change that).
>>>
>>> So - for example - user searches for "SMITH"
>>> I'm looking for a script that would find any array objects that
>>> contain "SMITH" in array1 and put the corresponding objects (whole
>>> file names containg that name) to array2.
>>>
>>> hope I was clear enough...
>>>
>> So, what have you tried already?
>> This has the characteristics of a homework assignment...
>>
>> -david-
>>
>>
>
> yep, i have, tried in_array with no results...
>
> here's the pic of code... i'm a newbie at this...
>
> if (is_dir($dirlist)==true ) {
> chdir( $dirlist );
> $handle=opendir( ".");
> }
> $x=0;
> $images=array();
> while (($file = readdir($handle))!==false) {
> $pieces = explode (".", $file);
> if ($pieces[0] && $pieces[1]) {
> if (($pieces[1]=="gif") || ($pieces[1]=="jpg") || ($pieces[1]=="GIF")
> || ($pieces[1]=="JPG") || ($pieces[1]=="bmp") || ($pieces[1]=="BMP") ||
> ($pieces[1]=="png") || ($pieces[1]=="PNG")) {
> $images[$x]=$file;
> $x++;
> }
> }
> }
> closedir($handle);
> }
> else
> {
> $images = unserialize(base64_decode($myArrayS));
> }
> echo "";
> $players=array();
> for ($i=0; $i<sizeof($images); $i++)
> {
> if (in_array($playername,$images)) { $players[i]= $images[i]; }
>
> echo "Foundnd : <B>".$players[$i]."</B><BR>";
>
> }
OK, so now we have something to talk about.

$x = 0;
while( ($file = readdir($handle)) != false ) {
$p = explode('.', $file);
if( !$p[0] || !$p[1] ) continue;
switch(strtolower($p[1])) {
case 'gif':
case 'jpg':
case 'bmp':
case 'png':
$images[$x++] = $file;
break;
default:
$images = unserialize(base64_decode($myArrayS));
break;
}
}
closedir($handle);

Will handle the first part.

$i = 0;
foreach( $images in $image ) {
if( in_array($image, $playername) ) {
players[$i++] = $image;
}
printf("Found <B>%s</B><BR>\n", $image);
}

Will handle the second part assuming $playername is an array.

-david-

 

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

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