Jump to content

Glob Regex


The Little Guy

Recommended Posts

glob works just like that.

 

I have the following files

 

test/bg1.txt, test/bg2.txt, test/bg3.txt, test/bg4.txt, test/cat.txt and test/africa.txt

 

Using the following code:

 

<?php print_r(glob('test/bg*.txt')); ?>

 

I get the following results:

Array
(
    [0] => test/bg1.txt
    [1] => test/bg2.txt
    [2] => test/bg3.txt
    [3] => test/bg4.txt
)

 

Obviously you would just change .txt to .jpg

Link to comment
https://forums.phpfreaks.com/topic/208068-glob-regex/#findComment-1087630
Share on other sites

Actually, since you only want numbers after bg, my previous post would do anything bg* really. Here is the modified version.

 

<?php print_r(glob('test/bg{[0-9]*}.txt',GLOB_BRACE)); ?>

 

Returns

Array
(
    [0] => test/bg1.txt
    [1] => test/bg12.txt
    [2] => test/bg2.txt
    [3] => test/bg3.txt
    [4] => test/bg4.txt
)

Link to comment
https://forums.phpfreaks.com/topic/208068-glob-regex/#findComment-1087632
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.