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
  • 46,141
  • 7
  • 83
  • 96
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
  • 418,526
  • 129
  • 929
  • 1,058