PDA

View Full Version : Really Basic Question about PHP includes


cheat-master30
10-21-2007, 07:39 PM
Note: No scripting is being run using includes by myself, nor anyone else. This is on including plain HTML files, not programs/scripts/etc.

What is the difference between all these ways of writing includes?

On W3Schools, they use this code:

<?php include("menu.php"); ?>

PHP.net uses this code:

include 'vars.php';

And some books use this code:

<?php include "menu.php"; ?>

Some use brackets and speech marks, some quotation marks and some either speech marks or quotations marks without brackets. Is there a specific standard in this respect, or is it a matter of choice which varies from tutorial to tutorial?

The second thing is this. Why do many books go back on what they say about security and Super Globals in later examples?

Marco van Herwaarden
10-22-2007, 05:35 AM
These are all valid, but the prefered syntax is:

include("filename");

Dismounted
10-23-2007, 06:50 AM
The <?php and ?> tags specify the start and end of where PHP should start processing code.

Opserty
10-23-2007, 09:56 AM
The second thing is this. Why do many books go back on what they say about security and Super Globals in later examples?
The are outdated? or a bit Lazy? or a bit of both :p. The internet may not be the most trusted place but its definitely the most in-line with the current standards and methods. ;)

Oh I and prefer using single quotes inside brackets...it looks far clean then double quotes. include('file.php'); :p

Dismounted
10-23-2007, 10:21 AM
Single quotes when not parsing variables, double when.

Opserty
10-23-2007, 10:54 AM
Single quotes when not parsing variables, double when.
In that case I prefer to leave the single quotes, stick in the variable then re-open them. Shows up far better under syntax highlighting too. :p require_once('functions_'. $file .'.php');