getPageFiles (function)

Last updated: Fri, May 26, 2023 8:53 am
Return to Knowledgebase


Retrieves a list of PHP files located in a specified directory. It then modifies the file paths to make them relative to the UserSpice installation directory.




This function does not take any arguments


Data Type Description of Returned Data
array The function returns an associative array ($row) where the keys and values are the modified file paths. The keys represent the modified file paths, and the values are identical to the keys in this case. Both keys and values are strings.

Further Documentation:

 function getPageFiles()
$directory = '../'; // The directory to search for PHP files
$pages = glob($directory . '*.php'); // Get all PHP files in the directory

$row = array(); // Initialize an empty array to store the modified file paths

foreach ($pages as $page) {
$fixed = str_replace('../', '/'.$us_url_root, $page); // Modify the file path
$row[$fixed] = $fixed; // Add the modified file path to the array

return $row; // Return the array of modified file paths

To use this function, you would need to include the file where the function is defined and then call the function like this:
// Include the file containing the getPageFiles function
require_once 'path/to/getPageFiles.php';

// Call the function to get the modified file paths
$pageFiles = getPageFiles();

// Iterate over the returned array of file paths
foreach ($pageFiles as $file) {
echo $file . '
'; // Output the modified file paths

Make sure to replace 'path/to/getPageFiles.php' with the actual path to the file where the getPageFiles function is defined.