πŸŽ“ A1Learner
πŸ”
0 of 40 lessons completed

PHP Introduction

PHP is a programming language used to build web pages. Each program in this course is one small complete file.

A first program

A PHP program is plain text that a server can run. This program prints one line of text.

<?php
echo "My first PHP program\n";

Two lines in order

Two echo statements run in order. The first line prints before the second line.

<?php
echo "First line from PHP\n";
echo "Second line from PHP\n";

Example

<?php
echo "PHP is a programming language\n";
echo "PHP files end in .php\n";
echo "PHP can print text\n";

Key points

  • PHP code is plain text in a file.
  • PHP files use the .php ending.
  • The <?php tag opens a block of PHP code.
  • echo prints text.
  • A server runs PHP before a page is sent.

In this example, three echo statements run in order. The first statement prints a line that names PHP as a programming language. The second statement prints the file ending line. The third statement prints a line about printing text.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does the echo statement do in PHP?