Hands-on with PHP — Home

Breaking the Ice

Hi there! Welcome to Hands-on with PHP.

First, let me introduce myself — copy the code in the About Me code section to the code editor of the PhpFiddle widget, then hit the Run button:

<?php
echo "<h2>About Me</h2>";
echo "<p>Hello, my name is <i>Peter Leow</i>.</p>";
echo "<p>I am a knowledge engineer, software developer, system analyst, teacher, and writer all in one.</p>";
?>

Unknowingly, you have just executed your first PHP script that outputs my self-introduction as web content in the browser.

In this script, there are three PHP statements as follows:

  • echo "<h2>About Me</h2>";
  • echo "<p>Hello, my name is <i>Peter Leow</i>.</p>";
  • echo "<p>I am a knowledge engineer, software developer, system analyst, teacher, and writer all in one.</p>";

The echo is the PHP command that outputs the data to the browser, the data consist of the respective texts together with their HTML markup as follows:

  • <h2>About Me</h2>
  • <p>Hello, my name is <i>Peter Leow</i>.</p>
  • <p>I am a knowledge engineer, software developer, system analyst, teacher, and writer all in one.</p>

Note that:

Each of these statements ends with a semicolon (;).

Each of them is also enclosed in a pair of <?php and ?> delimiters.

What happens if you remove some of the ; or either or both of the <?php and ?> delimiters? Doing is believing, figure it out yourself by modifying the code under the About Me code section. Specifically, you should find out the answers to the following quizzes:

Quiz

What happens if you omit only the first semicolon?
It complained about some syntax errors.
Correct!
It worked like a charm.
Wrong!
What happens if you omit only the last semicolon?
It worked like a charm.
Correct!
It complained about some syntax errors.
Wrong!
What happens if you omit both the last semicolon and the ?> delimiter?
It complained about some syntax errors.
Correct!
It worked like a charm.
Wrong!

About You

Using my self-introduction as an example, it’s your turn now to write a PHP script in the PhpFiddle widget to output an introduction of yourself You may begin…

Inline Code Editor

You have used the PhpFiddle widget, courtesy of the phpfiddle.org, to write and test PHP code. You will be using it very frequently in subsequent lessons to write and test PHP code as you learn.

Going Forward…

Tagged with:

Speak Your Mind