Skip to Content
PHP and MySQL® 24-Hour Trainer
book

PHP and MySQL® 24-Hour Trainer

by Andrea Tarr
November 2011
Beginner
504 pages
11h 30m
English
Wrox
Content preview from PHP and MySQL® 24-Hour Trainer

Lesson 3

Learning PHP Syntax

You‘ve seen how PHP can work on a web page. Now it's time to learn some basics of coding in PHP before you get into the detail of the language.

In this lesson you find out about formatting styles for PHP. You learn the general rules of PHP syntax and how to create comments. You learn the specific syntax of different PHP elements as you go over them in subsequent chapters.

Finally, you learn some best practices to make life easier and your code better.

Picking a Formatting Style

When you read a book or type a letter you are used to certain conventions. For instance, each paragraph might have the first line indented and a space before the next paragraph. Each chapter might start with the first letter enlarged.

Styling makes the text easier to understand because it organizes the information and tells you what to expect. If there are no paragraphs, if all the sentences continue one after the other without a break, you can read it but it is more difficult.

Programming uses formatting styles in the same way. The program runs fine without using any formatting but it is more difficult for a human being to read. It is harder to see what is happening and harder to find errors.

A computer has no trouble reading this code:

 <?php $messages=‘';$task=filter_input(INPUT_POST,'task',FILTER_SANITIZE_ STRING);if ($task=='product.maint'):$results=maintProduct();$a==true;$mess ages .=$results;endif;if ('contact.maint'):$results=maintContact();$messa ges .=$results;endif;if ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Expert PHP and MySQL®

Expert PHP and MySQL®

Andrew Curioso, Ronald Bradford, Patrick Galbraith

Publisher Resources

ISBN: 9781118066881Purchase book