Download Full Programming PHP 4th Edition Peter Macintyre PDF All Chapters
Download Full Programming PHP 4th Edition Peter Macintyre PDF All Chapters
com
https://textbookfull.com/product/programming-php-4th-
edition-peter-macintyre/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/programming-language-concepts-peter-
sestoft/
textboxfull.com
https://textbookfull.com/product/lumen-programming-guide-writing-php-
microservices-rest-and-web-service-apis-1st-edition-paul-redmond-auth/
textboxfull.com
https://textbookfull.com/product/programming-wcf-services-4th-edition-
juval-lowy/
textboxfull.com
Programming in Lua 4th Edition Roberto Ierusalimschy
https://textbookfull.com/product/programming-in-lua-4th-edition-
roberto-ierusalimschy/
textboxfull.com
https://textbookfull.com/product/computer-programming-and-
utilization-4e-4th-edition-e-balagurusamy/
textboxfull.com
https://textbookfull.com/product/advanced-apex-programming-in-
salesforce-4th-edition-dan-appleman/
textboxfull.com
1. Foreword
2. Preface
a. Audience
b. Assumptions This Book Makes
c. Contents of This Book
d. Conventions Used in This Book
e. O’Reilly Online Learning
f. How to Contact Us
g. Acknowledgments
i. Kevin Tatroe
ii. Peter MacIntyre
3. 1. Introduction to PHP
a. What Does PHP Do?
b. A Brief History of PHP
i. The Evolution of PHP
ii. The Widespread Use of PHP
c. Installing PHP
d. A Walk Through PHP
i. Configuration Page
ii. Forms
iii. Databases
iv. Graphics
e. What’s Next
4. 2. Language Basics
a. Lexical Structure
i. Case Sensitivity
ii. Statements and Semicolons
iii. Whitespace and Line Breaks
iv. Comments
v. Literals
vi. Identifiers
vii. Keywords
b. Data Types
i. Integers
ii. Floating-Point Numbers
iii. Strings
iv. Booleans
v. Arrays
vi. Objects
vii. Resources
viii. Callbacks
ix. NULL
c. Variables
i. Variable Variables
ii. Variable References
iii. Variable Scope
iv. Garbage Collection
d. Expressions and Operators
i. Number of Operands
ii. Operator Precedence
iii. Operator Associativity
iv. Implicit Casting
v. Arithmetic Operators
vi. String Concatenation Operator
vii. Auto-Increment and Auto-Decrement Operators
viii. Comparison Operators
ix. Bitwise Operators
x. Logical Operators
xi. Casting Operators
xii. Assignment Operators
xiii. Miscellaneous Operators
e. Flow-Control Statements
i. if
ii. switch
iii. while
iv. for
v. foreach
vi. try...catch
vii. declare
viii. exit and return
ix. goto
f. Including Code
g. Embedding PHP in Web Pages
i. Standard (XML) Style
ii. SGML Style
iii. Echoing Content Directly
h. What’s Next
5. 3. Functions
a. Calling a Function
b. Defining a Function
c. Variable Scope
i. Global Variables
ii. Static Variables
d. Function Parameters
i. Passing Parameters by Value
ii. Passing Parameters by Reference
iii. Default Parameters
iv. Variable Parameters
v. Missing Parameters
vi. Type Hinting
e. Return Values
f. Variable Functions
g. Anonymous Functions
h. What’s Next
6. 4. Strings
a. Quoting String Constants
i. Variable Interpolation
ii. Single-Quoted Strings
iii. Double-Quoted Strings
iv. Here Documents
b. Printing Strings
i. echo
ii. print()
iii. printf()
iv. print_r() and var_dump()
c. Accessing Individual Characters
d. Cleaning Strings
i. Removing Whitespace
ii. Changing Case
e. Encoding and Escaping
i. HTML
ii. URLs
iii. SQL
iv. C-String Encoding
f. Comparing Strings
i. Exact Comparisons
ii. Approximate Equality
g. Manipulating and Searching Strings
i. Substrings
ii. Miscellaneous String Functions
iii. Decomposing a String
iv. String-Searching Functions
h. Regular Expressions
i. The Basics
ii. Character Classes
iii. Alternatives
iv. Repeating Sequences
v. Subpatterns
vi. Delimiters
vii. Match Behavior
viii. Character Classes
ix. Anchors
x. Quantifiers and Greed
xi. Noncapturing Groups
xii. Backreferences
xiii. Trailing Options
xiv. Inline Options
xv. Lookahead and Lookbehind
xvi. Cut
xvii. Conditional Expressions
xviii. Functions
xix. Differences from Perl Regular Expressions
i. What’s Next
7. 5. Arrays
a. Indexed Versus Associative Arrays
b. Identifying Elements of an Array
c. Storing Data in Arrays
i. Appending Values to an Array
ii. Assigning a Range of Values
iii. Getting the Size of an Array
iv. Padding an Array
d. Multidimensional Arrays
e. Extracting Multiple Values
i. Slicing an Array
ii. Splitting an Array into Chunks
iii. Keys and Values
iv. Checking Whether an Element Exists
v. Removing and Inserting Elements in an Array
f. Converting Between Arrays and Variables
i. Creating Variables from an Array
ii. Creating an Array from Variables
g. Traversing Arrays
i. The foreach Construct
ii. The Iterator Functions
iii. Using a for Loop
iv. Calling a Function for Each Array Element
v. Reducing an Array
vi. Searching for Values
h. Sorting
i. Sorting One Array at a Time
ii. Natural-Order Sorting
iii. Sorting Multiple Arrays at Once
iv. Reversing Arrays
v. Randomizing Order
i. Acting on Entire Arrays
i. Calculating the Sum of an Array
ii. Merging Two Arrays
iii. Calculating the Difference Between Two Arrays
iv. Filtering Elements from an Array
j. Using Arrays to Implement Data Types
i. Sets
ii. Stacks
k. Implementing the Iterator Interface
l. What’s Next
8. 6. Objects
a. Objects
b. Terminology
c. Creating an Object
d. Accessing Properties and Methods
e. Declaring a Class
i. Declaring Methods
ii. Declaring Properties
iii. Declaring Constants
iv. Inheritance
v. Interfaces
vi. Traits
vii. Abstract Methods
viii. Constructors
ix. Destructors
f. Anonymous Classes
g. Introspection
i. Examining Classes
ii. Examining an Object
iii. Sample Introspection Program
h. Serialization
i. What’s Next
9. 7. Dates and Times
a. What’s Next
10. 8. Web Techniques
a. HTTP Basics
b. Variables
c. Server Information
d. Processing Forms
i. Methods
ii. Parameters
iii. Self-Processing Pages
iv. Sticky Forms
v. Multivalued Parameters
vi. Sticky Multivalued Parameters
vii. File Uploads
viii. Form Validation
e. Setting Response Headers
i. Different Content Types
ii. Redirections
iii. Expiration
iv. Authentication
f. Maintaining State
i. Cookies
ii. Sessions
iii. Combining Cookies and Sessions
g. SSL
h. What’s Next
11. 9. Databases
a. Using PHP to Access a Database
b. Relational Databases and SQL
i. PHP Data Objects
c. MySQLi Object Interface
i. Retrieving Data for Display
d. SQLite
e. Direct File-Level Manipulation
f. MongoDB
i. Retrieving Data
ii. Inserting More Complex Data
g. What’s Next
12. 10. Graphics
a. Embedding an Image in a Page
b. Basic Graphics Concepts
c. Creating and Drawing Images
i. The Structure of a Graphics Program
ii. Changing the Output Format
iii. Testing for Supported Image Formats
iv. Reading an Existing File
v. Basic Drawing Functions
d. Images with Text
i. Fonts
ii. TrueType Fonts
e. Dynamically Generated Buttons
i. Caching the Dynamically Generated Buttons
ii. A Faster Cache
f. Scaling Images
g. Color Handling
i. Using the Alpha Channel
ii. Identifying Colors
iii. True Color Indexes
iv. Text Representation of an Image
h. What’s Next
13. 11. PDF
a. PDF Extensions
b. Documents and Pages
i. A Simple Example
ii. Initializing the Document
iii. Outputting Basic Text Cells
c. Text
i. Coordinates
ii. Text Attributes
iii. Page Headers, Footers, and Class Extension
iv. Images and Links
v. Tables and Data
d. What’s Next
Copyright © 2020 Kevin Tatroe and Peter MacIntyre. All rights reserved.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://oreilly.com). For more
information, contact our corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
The views expressed in this work are those of the authors, and do not represent the
publisher’s views. While the publisher and the authors have used good faith efforts to
ensure that the information and instructions contained in this work are accurate, the
publisher and the authors disclaim all responsibility for errors or omissions, including
without limitation responsibility for damages resulting from the use of or reliance on
this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject
to open source licenses or the intellectual property rights of others, it is your
responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-492-05413-9
[LSI]
Dedication
To Jenn
—KT
—PBM
Foreword
It’s hard to believe that nearly 20 years ago I picked up my first PHP book. I had an
interest in programming, extending beyond Netscape Composer and static HTML. I
knew PHP would enable me to create dynamic, smarter websites—and to store and
fetch data to create interactive web applications.
What I didn’t know was the journey that unlocking these new capabilities with PHP
would take me on, or how PHP would evolve 20 years later to become the
programming language powering roughly 80% of the web, and backed by one of the
nicest, friendliest, and most engaging communities.
As you get ready to begin this journey, I would like to share a couple tidbits of advice.
First, take each chapter and put it into practice, try different things, and don’t be afraid
of breaking something or failing. While Programming PHP will establish a strong
foundation, it’s up to you to explore the language and find new and creative ways to
pull together all of these components.
My second piece of advice: be an active part of the PHP community. Take advantage of
online communities, user groups, and PHP conferences as you are able. As you try new
things, share them with the community for their feedback and advice.
Not only are you sure to find a community of support—a group of some of the nicest
people, who want you to succeed and are more than happy to take their time to help you
through your journey—but you’ll also establish a baseline of continuous learning,
helping you grasp the core skills of PHP more quickly and keeping you up to date on
new programming theories, technologies, tools, and changes. Not to mention, you’ll
encounter an onslaught of terrible puns (including from yours truly).
With that, I would like to be among the first to welcome you and to wish you the very
best on your journey—a journey that couldn’t start off better than with this book!
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).
Chapter 4, Strings
Covers the functions you’ll use when building, dissecting, searching, and modifying
strings in your PHP code.
Chapter 5, Arrays
Details the notation and functions for constructing, processing, and sorting arrays in
your PHP code.
Chapter 6, Objects
Covers PHP’s updated object-oriented features. In this chapter, you’ll learn about
classes, objects, inheritance, and introspection.
Chapter 7, Dates and Times
Discusses date and time manipulations like time zones and date math.
Chapter 8, Web Techniques
Talks about techniques most PHP programmers eventually want to use, including
processing web form data, maintaining state, and dealing with SSL.
Chapter 9, Databases
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, Graphics
Demonstrates how to create and modify image files in a variety of formats from
within PHP.
Chapter 11, PDF
Explains how to create dynamic PDF files from a PHP application.
Chapter 12, XML
Introduces PHP’s extensions for generating and parsing XML data.
Chapter 13, JSON
Covers JavaScript Object Notation (JSON), a standardized data-interchange format
designed to be extremely lightweight and human-readable.
Chapter 14, Security
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, Application Techniques
Talks about coding techniques like implementing code libraries, dealing with output
in unique ways, and error handling.
Chapter 16, Web Services
Describes techniques for dealing with external communication via REST tools and
cloud connections.
Chapter 17, Debugging PHP
Discusses techniques for debugging PHP code and for writing debuggable PHP
code.
Chapter 18, PHP on Disparate Platforms
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.
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.
SUPPORTING A
GOOD WARDEN
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com