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

Asked

Viewed 70 times

2

I am using PHP, and in a server folder contain 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]

every word of this among the @ means something by 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 he did it, GEOTIMBRAG1A is the name of the host Disco the type and .json is the file extension.

i need to assign to an array all filenames that are from id T9997012 being 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 could not.

I also need an array with all the hosts (GEOTIMBRAG1A) of all the files of an id. later I will need an array with all type (disk, Panserver) of an id.

  • think the glob command should help $files = glob("/path/to/directory/* geotimbering*.*");

1 answer

6


You can use the function glob().

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

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

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

For example, to capture all with the host GEOTIMBRAG1A

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.