Hi I want to use this include include("./directory/folder/$town.php") (I Have taken away the PHP tags) if $town does not exist is there a way of bypassing the include so the page still loads correctly? I am getting the variable from the URL Jamie (fingers crossed)
You can check to see if the file exists with the file_exists function before trying to include it. If the file exists, include the file, otherwise do nothing. $file = "./directory/folder/" . $town . ".php"; if (file_exists($file)) { include ($file); } PHP:
Just and fyi.. include is not a function, it's a special construct that doesn't require you to use the () as their use impacts how the construct evaluates the include. include 'filename.php'; is all you need to do.