PHP glob patter issue -


Hi, I am trying to use some files in my directory using the globe.

My pattern is like

  foreach (globe (root. "../test/te[0-9] {2} .xml") $ filename ) {Echo $ filename; }   

files are

  0051_001.xml 0071_001_as01.xml 0485_001_te01.xml 0485_001_te02.xml 0485_001_teh03.xml   

It does not do anything

I should only teh01 to te03.xml , but not the rest. I am not sure what is wrong with me? Can anyone help me in this matter? Thanks a lot!

globe does not support [0-9] { 2} , you must type [0-9] [0- 9] :

  foreach (globe ($ root. "../test /te[0-9][0-9].xml ") as $ filename) {echo $ filename; }   

For your files, you need to use:

  foreach (globe ($ root. "../ test / [0- 9] [0-9] [0- 9] [0- 9] _ [0-9] [0-9] [0-9] _te [0-9] [0-9] .xml ") $ Filename) {$ Filename echo; }   

Or you can add a regex check:

  foreach (globe ($ root. "../test/*.xml") $ As file name) {if (preg_match ('/ _ te \ d {2}. Xml $ /', $ filename, $ matches}) {echo $ filename; }}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -