This book is intended for anyone starting out with PHP programming. If you’ve previously worked in another programming language such as Java, C#, or Perl, you’ll probably pick up the concepts in the earlier chapters quickly; however, the book assumes no prior experience of programming or of building Web applications.
That said, because PHP is primarily a Web technology, it will help if you have at least some knowledge of other Web technologies, particularly HTML and CSS.
Many Web applications make use of a database to store data, and this book contains three chapters on working with MySQL databases. Once again, if you’re already familiar with databases in general — and MySQL in particular — you’ll be able to fly through these chapters. However, even if you’ve never touched a database before in your life, you should still be able to pick up a working knowledge by reading through these chapters.
What This Book Covers
This book gives you a broad understanding of the PHP language and its associated technologies. You explore a wide range of topics, including:
- installing a copy of the PHP engine on Ubuntu Linux, Windows, and Mac OS X; other ways you can install or use PHP; how to write a simple PHP script.
- basic PHP language concepts. variables, data types, operators, expressions, and constants.
- how to change the flow of your scripts by creating decisions and loops. if, else, and switch statements; the ternary operator; and the do, while, for, break, and continue statements. how to nest loops, and how to mix decisions and looping with blocks of HTML.
- PHP’s handling of strings, or sequences of characters; how to create strings; how to retrieve characters from a string; and how to manipulate strings with functions such as strlen(), substr(), strstr(), strpos(), str_replace(), and printf(), to name but a few.
- arrays — variables that can hold multiple values. You learn the difference between indexed and associative arrays, and find out how to create arrays and access their individual elements; array manipulation, including functions such as print_r(), array_slice(), count(), sort(), array_merge(), and list(). You also learn how to create foreach loops, as well as how to work with multidimensional arrays.
- functions — blocks of code that you can use again and again. You look at how to call built-in functions, and how to work with variable functions. You also study how to create your own functions, including defining parameters, returning values, understanding scope, and using anonymous functions. Other function-related topics such as references and recursion are also explored.
- object-oriented programming. You look at the advantages of an object-oriented approach, and learn how to build classes, properties, and methods, and how to create and use objects. You also explore more advanced topics such as overloading, inheritance, interfaces, constructors and destructors, autoloading, and namespaces.
- how to use PHP to create interacti