Steve
Steve

Reputation: 4213

What does "#include "myfile.php" do?

What's the meaning of the # symbol in the following line of php code:

#include "myfile.php";

Upvotes: 0

Views: 270

Answers (6)

Hamid Nazari
Hamid Nazari

Reputation: 3985

It works as a single line comment, exactly as // does.

In order to include a file, use

include("myfile.php"); # or
require("myfile.php"); # dies if fails to include

Upvotes: 0

Adam Lear
Adam Lear

Reputation: 38768

It marks the line as a comment, so the include directive isn't actually executed.

In the code below only myfile1.php will be included:

<?php
include "myfile1.php";
// include "myfile2.php";
# include "myfile3.php";
?>

Upvotes: 1

Martin Bean
Martin Bean

Reputation: 39389

The hash is simply a single-line comment character.

Upvotes: 1

Jon Weers
Jon Weers

Reputation: 1631

# is a single line comment. It means that line of code is not being used.

Upvotes: 1

SilentGhost
SilentGhost

Reputation: 319601

means that the line is commented out.

Upvotes: 3

Piskvor left the building
Piskvor left the building

Reputation: 92762

Comments it out - this is a "Perl-style comment", with the same function as the "C-style comment" //. See the documentation for different ways of commenting in PHP.

Upvotes: 9

Related Questions