How to check if a file containing a specific word exists?

2

I'm using PHP, and in a server folder it contains files with these names:

T3497012@16-01-02:21@[email protected]
T3497012@16-01-02:22@[email protected]
T3497012@16-01-02:23@[email protected]
T3497012@16-01-02:24@[email protected]
T3497012@16-01-02:25@[email protected]
T3497012@16-01-02:26@[email protected]
T3497012@16-01-02:27@[email protected]
T3497012@16-01-02:28@[email protected]
T9997012@16-01-02:29@[email protected]
T1997012@16-01-02:30@[email protected]
T1997012@16-01-02:31@[email protected]
T9997012@16-01-02:32@[email protected]
T9997012@16-01-02:33@[email protected]

Each word of this between @ means something, analyzing the first file for example:

T3497012@16-01-02:21@[email protected]

T3497012 is the id of the user who saved the file, 16-01-02:21 is the date and time it did it, GEOTIMBRAG1A is the host name Disco type and .json is the extension of the file.

I need to assign to an array all filenames that are of the T9997012 id like this:

$array[0] = "T9997012@16-01-02:29@[email protected]";
$array[1] = "T9997012@16-01-02:32@[email protected]";
$array[2] = "T9997012@16-01-02:33@[email protected]";

I tried to use preg_match () but I could not.

I also need an array with all hosts (GEOTIMBRAG1A) of all the files in an id. later I'll need an array with all type (disk, Panser) of an id.

    
asked by anonymous 16.01.2018 / 20:27

1 answer

6

You can use the glob() function.

To get all the files of the ID T9997012 , you can use wildcard * , for example:

$array = glob('T9997012*.*');

In all other cases at the end of the question you can use the same idea.

For example, to capture all with host GEOTIMBRAG1A

$array = glob('*GEOTIMBRAG1A*.*');
    
16.01.2018 / 20:33