tags:

views:

42

answers:

2
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  A: 
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
+2  A: 

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.

Pekka
:)‍‍‍‍‍‍‍‍‍‍‍‍‍
Gumbo