Book Image

Practical Web Development

By : Paul Wellens
Book Image

Practical Web Development

By: Paul Wellens

Overview of this book

Table of Contents (23 chapters)
Practical Web Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
10
XML and JSON
Index

Introduction to PHP


As we mentioned, PHP, like JavaScript, is a language that is interpreted. So, we need an interpreter first. With JavaScript, that was easy, the interpreter is inside any browser. With PHP, you need a separate program to interpret your code. Assume you have such a program called php on your computer (I have one on my Mac) where you can type in PHP code or supply a file with the code inside it, then we could write our first program.

Our first, not so useful, example: using your favorite editor, create a file called first.php and enter the following text:

<?php
echo "Hello, world";
?>

Notice the strings <?php and ?>. Typically, PHP code is placed in between those strings. So both examples really contain only a single line of PHP code.

So, if you have that php program on your computer (don't panic if you don't, you are not going to need one), you can type php first.php and you will see Hello, world appear on your screen.

As PHP is a full-featured language, you could...