11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSYou can also execute include() statements conditionally. For example, if an include() statement isplaced in an if statement, the file will be included only if the if statement in which it is enclosedevaluates to true. One quirk regarding the use of include() in a conditional is that it must be enclosed instatement block curly brackets or in the alternative statement enclosure. Consider the difference insyntax between the following two code snippets. The first presents incorrect use of conditionalinclude() statements due to the lack of proper block enclosures:The next snippet presents the correct use of conditional include() statements by properly enclosingthe blocks in curly brackets:One misconception about the include() statement is the belief that because the included code willbe embedded in a <strong>PHP</strong> execution block, the <strong>PHP</strong> escape tags aren’t required. However, this is not so; thedelimiters must always be included. Therefore, you could not just place a <strong>PHP</strong> command in a file andexpect it to parse correctly, such as the one found here:echo "this is an invalid include file";Instead, any <strong>PHP</strong> statements must be enclosed with the correct escape tags, as shown here:■ Tip Any code found within an included file will inherit the variable scope of the location of its caller.If the <strong>PHP</strong> configuration directive allow_url_fopen is enabled, it’s possible to reference a remote filewithin an include() statement. If the resident server is <strong>PHP</strong>-enabled, any variables found within the87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!