Home Quizzes Leaderboard Competitions Learn Hire Us
About Contact
Log In Sign Up
Learn PHP Hello, PHP! --- Your First Script

Hello, PHP! --- Your First Script

⏱ 10 min read read
What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language
designed for web development. It powers over 75% of the web ---
including WordPress, Facebook (historically), and Wikipedia.

How PHP Works:

PHP runs on the server, not in the browser. When a user visits a PHP
page, the server executes the PHP code and sends plain HTML back to the
browser. The user never sees the PHP code.

PHP files use the .php extension.

All PHP code lives inside <?php ... ?> tags.

Run locally with: php hello.php (in terminal)

Or serve with: php -S localhost:8000

Your First Script:

<?php

// Single-line comment

echo "Hello, World!";

/*

* Multi-line comment.

* PHP ignores everything in here.

*/

echo "Hello again!\n";

// print() is similar to echo but returns 1

print("Hello from print()\n");

// PHP_EOL is the system line ending constant

echo "Line ending: " . PHP_EOL;

?>

echo vs print:

echo --- outputs one or more strings, no return value, slightly faster.

print --- outputs one string, always returns 1 (can be used in
expressions).

Both accept strings with double quotes (variables interpolated) or
single quotes (literal).

IMPORTANT: Every PHP statement ends with a semicolon ;

Forgetting the semicolon is the #1 beginner error.

PHP is case-insensitive for keywords (echo, ECHO, Echo all work).

But variable names ARE case-sensitive: $name ≠ $Name

PHP vs Python --- Hello World:

Python: print("Hello, World!") --- one clean line, no tags.

PHP: <?php echo "Hello, World!"; ?> --- needs opening tag and
semicolon.

PHP is designed to be embedded in HTML --- that's why it needs
delimiters.
Code Example
<?php

// Single-line comment

echo "Hello, World!\n";

/*

* Multi-line comment

* PHP ignores everything in here.

*/

// echo can take multiple arguments

echo "Hello", " ", "PHP!", "\n";

// print() returns 1 --- usable in expressions

print("print() works too\n");

// String concatenation uses . (dot)

$name = "Alice";

echo "Hello, " . $name . "!\n";

// Double quotes interpolate variables

echo "Hello, $name!\n";

// PHP_EOL is the cross-platform newline

echo "Done" . PHP_EOL;

// Output:

// Hello, World!

// Hello PHP!

// print() works too

// Hello, Alice!

// Hello, Alice!

// Done

?>
← Back to Course Variables & Data Types →

Log in to track your progress and earn badges as you complete lessons.

Log In to Track Progress