0
if(!file_exists("dynamic/content_".$get.".html"))

This exists in a php file. I need to modify this line of code to also encompass being able to navigate to dynamic/content_whatever.php, not just .html.

What is the best way to do this? Thanks.

2 Answers2

2
if (file_exists("dynamic/content_".$get.".html")) {
    include "dynamic/content_".$get.".html";
} elseif (file_exists("dynamic/content_".$get.".php")) {
    include "dynamic/content_".$get.".php";
}
webbiedave
  • 48,414
  • 8
  • 88
  • 101
2

Make use of glob()'s awesome brace abilities:

if (count(glob("dynamic/content_$get.{php,html,txt,htm}", GLOB_BRACE)) == 0)
  ...

Hat tip to Gumbo

May be a bit slower than using file_exists(), as that function is very fast and additionally uses the stat cache, and as far as I know, glob() does not.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088