0

So let say we have a folder named "Template", inside this folder we have

Template -

home.php
about.php
contact.php

Now in index.php file, I want to call this php files, NOT the content of each files only the file name home about contact. So the output of index.php should be something like this:

HELLO WORLD! Here are the list of filenames inside the template folder!
HOME
ABOUT
CONTACT

I checked other answers here but it is not in PHP

ICG DEVS
  • 195
  • 3
  • 15
  • oh it has a duplicate, weird I was searching it a while ago but nothing php related is showing. Anyway thanks! – ICG DEVS Sep 22 '18 at 18:55

1 Answers1

1

You could use

array scandir ( string $directory [, int $sorting_order = SCANDIR_SORT_ASCENDING [, resource $context ]] )

Example:

<?php
$dir    = '/public';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

print_r($files1);
print_r($files2);
?>

Learn more here http://php.net/manual/en/function.scandir.php

ilovejq
  • 179
  • 1
  • 3
  • 11
  • I'm not sure if a simple copy of the docs makes this a good answer. At least get the folder name 'Template' right. And why once in asc, once in desc? Also I'm pretty sure the OP will complain about the '..' and '.' – Jeff Sep 22 '18 at 18:50
  • The possible duplicate comment above solves my problem, and @Jeff has a point, but this answer also helped me so I will upvote this once I reach 15 reputation. Thanks again! – ICG DEVS Sep 22 '18 at 18:59
  • @Jeff If it works, why complain? This isn't a message board. I provided OP with the correct response. Why do I have to justify myself by changing it up from the best source (the docs)? I helped. OP thanked me. Either contribute something positive or don't contribute at all. OP, if this solved your answer click the check mark next to it to mark as complete. – ilovejq Sep 22 '18 at 19:02