PHP tags
2
By default, a PHP file is assumed as HTML-file. To run a script, you should put it inside special PHP tags, just like that:
<html>
<head>
<title>My first PHP website</title>
</head>
<body>
<?php
echo 'Hello PHP!';
?>
</body>
</html>
In real-life websites you don't really mix HTML and PHP. Instead, you should keep pure PHP scripts and HTML templates separately. However for the learning purposes we will do it from time to time.
So, in the example above your PHP code surronded by PHP tags looks exactly like that:
<?php
echo 'Hello PHP!';
?>
echo
is a function that prints a given value. In our case it's Hello PHP!
string. Every PHP statement should end with a semicolon. And that's all we should learn in this lesson.
Rate this post:
Lesson 1
Lesson 3
Share this page:
Learning plan
1. Introduction
Choose the best way to start, and let's start!
2. PHP tags
Embedding PHP script into HTML
3. Variables
The very basics of PHP variables
4. Arrays
The very basics of PHP arrays
The things you should know about PHP type system
Cross related lessons
Pure HTML is boring, so let's add some styles — Lesson 4
There are a couple of SEO tips you should learn about right away — Lesson 3
HTML elements and the basic document structure — Lesson 2
What you're going to deal with — Lesson 1