Connecting Tech Pros Worldwide Forums | Help | Site Map

i will kill my(sql) self ! :-)

g0c
Guest
 
Posts: n/a
#1: Nov 22 '05
hi all,
i really cannot find a simple exmaple for preg_match function

i whiled the files in the directory ...

$d = dir('.') or die($php_errormsg);
while (false !== ($f = $d->read())) {
if (is_file($d->path.'/'.$f)) {
if (preg_match(match????,substr($f,3))) {
// print '<option> ' . $f . '<option>';
echo "$f\n";
}
}
}
$d->close();

i want to include files begining with "tn_"
what in the heck must stand in pattern position, i tried everything ,
nothing worked
i have actually 8 files starting with tn_* of course ...

thanks



g0c
Guest
 
Posts: n/a
#2: Nov 22 '05

re: i will kill my(sql) self ! :-)


"g0c" <REMOVEg0c@msn.com> wrote in message
news:dla9ra$19oe$1@fegnews.vip.hr...[color=blue]
> hi all,
> i really cannot find a simple exmaple for preg_match function
>
> i whiled the files in the directory ...
>
> $d = dir('.') or die($php_errormsg);
> while (false !== ($f = $d->read())) {
> if (is_file($d->path.'/'.$f)) {
> if (preg_match(match????,substr($f,3))) {
> // print '<option> ' . $f . '<option>';
> echo "$f\n";
> }
> }
> }
> $d->close();
>
> i want to include files begining with "tn_"
> what in the heck must stand in pattern position, i tried everything ,
> nothing worked
> i have actually 8 files starting with tn_* of course ...
>
> thanks
>[/color]

solved : thanks ... /me stupid

/tn.+/ is the solution


Ewoud Dronkert
Guest
 
Posts: n/a
#3: Nov 22 '05

re: i will kill my(sql) self ! :-)


g0c wrote:[color=blue]
> i want to include files begining with "tn_"[/color]

if (substr($fname, 0, 3) == 'tn_')

--
E. Dronkert
Oliver Grätz
Guest
 
Posts: n/a
#4: Nov 22 '05

re: i will kill my(sql) self ! :-)


g0c schrieb:[color=blue][color=green]
>>if (preg_match(match????,substr($f,3))) {[/color][/color]

Use preg_match("/^tn_.*/",$f);
Or even better, don't use preg_match for this easy case because the
suggested substr-only solution is significantly faster.

OLLi
Mladen Gogala
Guest
 
Posts: n/a
#5: Nov 22 '05

re: i will kill my(sql) self ! :-)


On Mon, 14 Nov 2005 16:18:02 +0100, g0c wrote:
[color=blue]
> i want to include files begining with "tn_"
> what in the heck must stand in pattern position, i tried everything ,
> nothing worked
> i have actually 8 files starting with tn_* of course ...[/color]

$files=glob('./tn_*');
foreach ($files as $f) {
print "$f\n";
}


If you kill yourself, may I have your stereo?


--
http://www.mgogala.com

Mladen Gogala
Guest
 
Posts: n/a
#6: Nov 22 '05

re: i will kill my(sql) self ! :-)


On Tue, 15 Nov 2005 01:46:25 +0100, Oliver Grätz wrote:
[color=blue]
> Use preg_match("/^tn_.*/",$f);[/color]

There is "glob" function borrowed from the older brother.

http://us2.php.net/manual/en/function.glob.php

--
http://www.mgogala.com

Closed Thread