Re: How would I get a list of all files matching a pattern?
- From: "Lars" <jon.doe@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Feb 2008 23:06:18 GMT
"laredotornado" <laredotornado@xxxxxxxxxxx> skrev i meddelandet
news: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.
See http://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
.
- Follow-Ups:
- Re: 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?
- References:
- How would I get a list of all files matching a pattern?
- From: laredotornado
- How would I get a list of all files matching a pattern?
- Prev by Date: How would I get a list of all files matching a pattern?
- Next by Date: preg_match_all issue, need some help
- Previous by thread: 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
|