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 05:04

oswald wrote:
> David Haynes <david.haynes2@sympatico.ca> napisal(a) w wiadomosci
> news:w7kwf.8107$Gm2.2510@fe47.usenetserver.com:
>
>
>> In that case, I'm not sure what you are trying to attempt in the second
>> part. Perhaps you could elaborate?
>>
>> -david-
>>
>>
> ok.
>
> the user inputs the player name ( $playername - string )he wants to find.
> the script is searching for the string among the files in the current
> directory (jpg files, every single one contains a name in the filename -
> for example JOHN_SMITH.jpg).
>
> so what i'm trying to do is :
>
> read directory -> put file names in array - part one
>
> second part
> search for $playername in $images
> if any part of $playername is found within that array ($images()) then
> put the whole record it was found in a new array - ($players()) and then
> display contents (full file names) on the screen.
>
> so if user inputs "SMITH" and one of the filenames in the array is
> JOHN_SMITH.jpg then put the JOHN_SMITH.jpg in the new array.
>
> hope I was clear enough.. as I said, i'm a noob ...

For the second part:
1. you have an array of the images in the directory
2. you have a playername (pattern) that you want to collect the matches for.

So,
$i=0;
foreach( $images as $image ) {
if( strstr($image, $playername) ) {
$players[$i++] = $image;
}
}

echo "I found: <br>\n";
echo "<pre>\n";
print_r($players);
echo "<\pre>\n";

 

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

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