Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions task1.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
<?
// Your code is here:
<?php
/**
* Find files in the /datafiles folder with names consisting of numbers and letters of the Latin alphabet,
* having the .ixt extension, and display the names of these files ordered by name.
*/

// Directory path to search for files
$directory = '/datafiles';

// Regular expression pattern to match files with names consisting of numbers and Latin alphabet letters with .ixt extension
$pattern = '/^[A-Za-z0-9]+\.ixt$/';

// Initialize an array to store file names that match the criteria
$matchingFiles = [];

// Get all files in the directory
$files = scandir($directory);

// Iterate through the files and match the pattern
foreach ($files as $file) {
if (preg_match($pattern, $file) && is_file($directory . '/' . $file)) {
$matchingFiles[] = $file; // Add the matching file to the array
}
}

// Sort the matching file names alphabetically
sort($matchingFiles);

// Display the sorted file names
foreach ($matchingFiles as $file) {
echo $file . PHP_EOL; // Display each file name
}