Preface

Now more than ever, the web is a major vehicle for corporate and personal communications. Websites carry satellite images of Earth in its entirety; search for life in outer space; house personal photo albums, business shopping carts, and product lists; and so much more! Many of those websites are driven by PHP, an open source scripting language primarily designed for generating HTML content.

Since its inception in 1994, PHP has swept the web and continues its phenomenal growth today. The millions of websites powered by PHP are testament to its popularity and ease of use. Everyday people can learn PHP and build powerful dynamic websites with it.

The core PHP language (version 7+) features powerful string- and array-handling facilities, as well as greatly improved support for object-oriented programming. With the use of standard and optional extension modules, a PHP application can interact with a database such as MySQL or Oracle, draw graphs, create PDF files, and parse XML files. You can run PHP on Windows, which lets you control other Windows applications (such as Word and Excel with COM) or interact with databases using ODBC.

This book is a guide to the PHP language. When you finish it (we won’t tell you how it ends!), you will know how the PHP language works, how to use the many powerful extensions that come standard with PHP, and how to design and build your own PHP web applications.

Audience

PHP is a melting pot of cultures. Web designers appreciate its accessibility and convenience, while programmers appreciate its flexibility, power, diversity, and speed. Both cultures need a clear and accurate reference to the language. If you are a (web) programmer, then this book is for you. We show the big picture of the PHP language, and then discuss the details without wasting your time. The many examples clarify the textual explanations; the practical programming advice and many style tips will help you become not just a PHP programmer, but a good PHP programmer.

If you’re a web designer, you will appreciate the clear and useful guides to specific technologies, such as JSON, XML, sessions, PDF generation, and graphics. And you’ll be able to quickly get the information you need from the language chapters, which explain basic programming concepts in simple terms.

This edition has been fully revised to cover the latest features of PHP version 7.4.

Assumptions This Book Makes

This book assumes you have a working knowledge of HTML. If you don’t know HTML, you should gain some experience with simple web pages before you try to tackle PHP. For more information on HTML, we recommend HTML & XHTML: The Definitive Guide by Chuck Musciano and Bill Kennedy (O’Reilly).

Contents of This Book

We’ve arranged the material in this book so that you can either read it from start to finish or jump around to hit just the topics that interest you. The book is divided into 18 chapters and 1 appendix, as follows:

Chapter 1
Talks about the history of PHP and gives a lightning-fast overview of what is possible with PHP programs.
Chapter 2
Is a concise guide to PHP program elements such as identifiers, data types, operators, and flow-control statements.
Chapter 3
Discusses user-defined functions, including scope, variable-length parameter lists, and variable and anonymous functions.
Chapter 4
Covers the functions you’ll use when building, dissecting, searching, and modifying strings in your PHP code.
Chapter 5
Details the notation and functions for constructing, processing, and sorting arrays in your PHP code.
Chapter 6
Covers PHP’s updated object-oriented features. In this chapter, you’ll learn about classes, objects, inheritance, and introspection.
Chapter 7
Discusses date and time manipulations like time zones and date math.
Chapter 8
Talks about techniques most PHP programmers eventually want to use, including processing web form data, maintaining state, and dealing with SSL.
Chapter 9
Discusses PHP’s modules and functions for working with databases, using MySQL database as examples. Also, SQLite and PDO database interface are covered. NoSQL concepts are also covered here.
Chapter 10
Demonstrates how to create and modify image files in a variety of formats from within PHP.
Chapter 11
Explains how to create dynamic PDF files from a PHP application.
Chapter 12
Introduces PHP’s extensions for generating and parsing XML data.
Chapter 13
Covers JavaScript Object Notation (JSON), a standardized data-interchange format designed to be extremely lightweight and human-readable.
Chapter 14
Provides valuable advice and guidance for programmers creating secure scripts. You’ll learn programming best practices to help you avoid mistakes that can lead to disaster.
Chapter 15
Talks about coding techniques like implementing code libraries, dealing with output in unique ways, and error handling.
Chapter 16
Describes techniques for dealing with external communication via REST tools and cloud connections.
Chapter 17
Discusses techniques for debugging PHP code and for writing debuggable PHP code.
Chapter 18
Discusses the tricks and traps of the Windows port of PHP. It also discusses some of the features unique to Windows, such as COM.
Appendix
Serves as a handy quick reference to all core functions in PHP.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Note

This icon signifies a tip, suggestion, general note, warning, or caution.

Using Code Examples

Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/title_title.

If you have a technical question or a problem using the code examples, please send email to .

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Programming PHP, Fourth Edition, by Kevin Tatroe and Peter MacIntyre (O’Reilly). Copyright 2020 Kevin Tatroe and Peter MacIntyre, 978-1-492-05413-9.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Acknowledgments

Kevin Tatroe

Once again, thanks to every individual who ever committed code to PHP, contributed to the vastness that is the PHP ecosystem, or wrote a line of PHP. You all made PHP what it was, is, and will continue to be.

To my parents, who once purchased a small LEGO set for a long and frightening plane trip, beginning an obsession with creativity and organization that continues to relax and inspire me to this day.

Finally, a heaping fourth spoonful of gratitude to Jenn and Hadden for helping inspire and encourage me through each and every day.

Peter MacIntyre

I would like to praise the Lord of Hosts who gives me the strength to face each day! He created electricity through which I make my livelihood; thanks and praise to Him for this totally unique and fascinating portion of His creation!

To Kevin, who is once again my main coauthor on this edition, thanks for the effort and once again staying focused on this project to its publication.

To the technical editors who sifted through our code examples and tested them to make sure we were “telling the truth”—Lincoln, Tanja, Jim, and James—thanks!

And finally to all those at O’Reilly who so often go unmentioned—I don’t know all your names, but I know what you have to do to get a project like this finally “out the door.” The editing, graphics work, layout, planning, marketing, and so on all has to be done, and I certainly appreciate all your hard work toward this end.

O’Reilly Online Learning

Note

For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed.

Our unique network of experts and innovators share their knowledge and expertise through books, articles, conferences, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, please visit http://oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/programming-PHP-4e.

Email to comment or ask technical questions about this book.

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.83.150