Re: How would I get a list of all files matching a pattern?
- From: laredotornado <laredotornado@xxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 08:28:44 -0800 (PST)
On Feb 27, 5:06 pm, "Lars" <jon....@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"laredotornado" <laredotorn...@xxxxxxxxxxx> skrev i meddelandetnews:4ed42954-f370-4941-a6e8-bda6628b0b90@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I'm using php 4.4.4. Given a directory $dir, and a prefix, $prefix,
how would I get all files matching the expression
$dir/$prefix%d.jpg
where %d is any unsigned integer?
Thanks, - Dave
Don't know what you mean. Is it a string value or is it in the include part
where you include files. Assuming you wan't to build a strin use the
following.
I think the function sprintf solves your problem easally.
Seehttp://se2.php.net/manual/sv/function.sprintf.php
$aStringValue = sprintf("%s/%s%d\.jpg", $dir,$prefix, $number );
// Don't knowif youca write a dot (.) after %d and get output as a dot.
// Hence the %d\.. YOu might have to use \ before /. Test and see.
To build a sqeuence of HTML links to images do the following.
$text = sprintf("<table>\n");
$text .= sprintf("<tr><td><h1>Links to my images</h1></td></tr>\n");
for ($i=0;$i<$nbImages;$i++)
{
$text .= sprintf("<tr><td><a href=\"%s/%s%d\.jpg\">Image
%3d</a></td></tr>\n", $dif, $prefix, $i );}
$text .= sprintf("</td></tr></table>\n");
// Text holds the HTML list of links to the images.
// Note %3d tells sprintf to writes $i as 001, 002, 003...
Lars
What I mean is let's say I have these files in a directory
/usr/local/apache2/htdocs/myfiles/file1.jpg
/usr/local/apache2/htdocs/myfiles/file2.jpg
/usr/local/apache2/htdocs/myfiles/file3.jpg
/usr/local/apache2/htdocs/myfiles/file4.jpg
The directory would be "/ur/local/apache2/htdocs/myfiles", the prefix
would be "file" and I'm looking for some way in PHP to return
"file1.jpg", "file2.jpg", "file3.jpg", and "file4.jpg", preferrably in
some kind of array.
Thanks, - Dave
.
- Follow-Ups:
- Re: How would I get a list of all files matching a pattern?
- From: Michael Fesser
- Re: How would I get a list of all files matching a pattern?
- References:
- How would I get a list of all files matching a pattern?
- From: laredotornado
- Re: How would I get a list of all files matching a pattern?
- From: Lars
- How would I get a list of all files matching a pattern?
- Prev by Date: Re: preg_match_all issue, need some help
- Next by Date: Re: How would I get a list of all files matching a pattern?
- Previous by thread: Re: How would I get a list of all files matching a pattern?
- Next by thread: Re: How would I get a list of all files matching a pattern?
- Index(es):
Relevant Pages
|