Download ebooks file Programming PHP 4th Edition Peter Macintyre all chapters
Download ebooks file Programming PHP 4th Edition Peter Macintyre 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.
Cable Web
The most popular web now made up into men’s garters is what is
known as the cable web, shown at Fig. 9. With the pronounced
prominence of the two-dent rib, which gives it a character peculiarly
different from the plain web, it is well adapted to this class of goods.
Simple in appearance, it nevertheless requires special care to
manufacture, particularly when we remember that it is not unusual to
be required to make a finished stretch of not less than 100 per cent.
The harness draft and weave are shown at Fig. 9A. The construction
is as follows: Binder, 34 ends 80/2; Gut, 24 ends 20/2; Rubber, 18
ends 28s; Reed, 20 dent; Picks, 80 per inch; Stretch, 100 per cent.
The filling, floating across the wide spaces under which lie the
rubber threads in pairs, is very easily thrown out of place, the result
of which may be an unsightly seersucker appearance, as shown in
Fig. 10, which the process of finishing aggravates rather than
corrects.
Trouble may manifest itself by the filling over the ribs opening up
and allowing the gut threads to prick through. To prevent this
objectionable feature it is necessary to use a good quality of
moderately soft yarn for the gut, not necessarily of high grade stock,
but a yarn which is uniformly spun and not at all hard or wiry. As
these goods are being woven and on full stretch, the gut threads, of
course, are perfectly straight and accurate in line, but when
contraction takes place, to probably one-half the former length, these
heavy threads, which form probably about 25 per cent. of the weight
of the entire web, should bend or fold uniformly and dispose of
themselves in such a manner as not to appear in any way on the
face of the web, snugly housed away in the several pockets or
cavities. If the yarn composing these gut threads is spotty or
irregularly spun, this uniformity of fold inside the pockets will be
broken up and the appearance of the face of the goods is likely to be
marred by unsightly specks of cotton pricking through, which can be
both seen and felt.
Chapter IV.
Elaboration of Honeycomb Effects by Parti-Dyed and Printed Fillings
—Bandage and Surgical Webs Made with Plain and Covered
Rubber—Frill Web Woven on Cam Looms—Double Cloths—
Importance of Securing Balance Between Back and Face of Goods
Among the group of single cloth webs confined to the capacity of
plain looms, is what is commonly known as the honeycomb, shown
at Fig. 1 and Fig. 1A. This is generally made with silk, wood silk, or
schappe filling. The smooth filling floating over two cords gives the
web a smooth feel, there being no rib effect noticeable whatever,
making it well adapted for a fine trade. The warp lines are almost
entirely hidden by the filling, so that it is not practicable to introduce
any sharp stripe fancy effects, which can be done both in the plain
web and the cable. The honeycomb is thus confined to plain solid
colors or such elaboration as can be obtained from the filling.
Fancy effects are often secured by dyeing skein yarn in two or
more colors. Such yarns when woven in the goods produce
alternating effects at regular distances in different colors, such
distances being governed by the length of the dips and the width of
the goods. The effects which can be produced are quite varied. The
simplest way of accomplishing this is to use the regular 54-inch
skein, having white or some light shade as a base, and then dyeing
a given portion of the skein another color. This process is carried out
by hanging the skeins on sticks placed in a rack at the required
distance above the color liquor, and then lowering them into the vat
and dyeing the immersed part in the usual manner.
Where cotton is used for the filling and more elaborate effects are
desired, long reeled skeins are used, sometimes 108 or 216 inches,
which have been reeled on specially designed collapsible reels.
Such skeins are not practicable to handle in the dye house in the
manner already described. Sections of such skeins are wrapped in
heavy waterproof paper and tied tightly, so that the dye liquor cannot
penetrate that portion, and then the whole is put in the liquor, when
the exposed part only will be dyed.
Then again sometimes wood clamps are used, like that shown at
Fig. 2, having a recess into which part of the skein is laid after being
carefully folded. The two halves are clamped together tightly in such
a manner that the dye cannot penetrate the clamped part of the
skein while the part left outside the clamp is dyed when the whole is
immersed in the dye liquor.
Printed Filling
Another form of elaboration used in such goods is printing the
skein yarn used for the filling. This is done by using a machine
having a pair of fluted brass printing rolls, one of which is made to
open on a hinge like a gate so that a skein of yarn can be put around
it. This roller is then closed to its original position, so that with the
two rollers parallel and close together, and the skein of yarn hugged
tightly between them, the turning of the rollers imprints color on the
skein. The skein is then taken out and dryed before spooling.
Different sets of rolls are used so as to get fine and coarse effects
and various colors are used in printing.
Where plaid or printed fillings are used for the elaboration of webs
of the honeycomb type, it is not unusual to introduce a couple of
plain cords in the center of the web, or possibly on either side, so as
to break up the flatness of the weave. This opens up the opportunity
of using lines of a different color in the warp which properly arranged
will produce a plaid-like effect.
Fig. 1.—Honeycomb
Bandage Webs
There is quite a large demand for surgical and bandage webs, Fig.
3, in widths ranging from 2 to 4 inches. These webs are used for
binding the limbs and other purposes and are in the pure white or
natural yarns. They require to be made with a long soft easy stretch.
An open reed of about 12 dents per inch is employed. Four threads
are generally used for the binder, weaving two up and two down. The
goods are similar in construction to a regular lisle web, except that
the gut is omitted in order to get the easiest possible movement.
Fig. 3.—Bandage Webs; Fabric at Left Made with Plain Rubber; Web at Right
Made With Covered Rubber
The yarn is generally the same quality and size for both warp and
filling, and is usually a soft spun 2-20s. The side of rubber is
generally about 38 or 40, with 40 picks per inch and a finished
stretch of 100 per cent. The use such webs are put to, necessitating
as we have already said a soft and sluggish stretch, prevents the
use of a heavy rubber thread, the result being that when the
bandage is kept in close contact with the warm body, the life of the
fine rubber is of short duration.
This condition, and the open weave necessary to get the easy
stretch, have made it expedient to use in many of these goods
strands of rubber which have been covered with cotton threads
before weaving. This process not only prolongs the life of the web,
but allows for even more open weaving, the use of different weaves
than would be possible where the uncovered rubber thread is used,
and the production of a fabric more suitable for the purpose.
In order to get the soft easy stretch which is the most desirable
characteristic of a bandage web, and yet have the necessary width,
it is not unusual to introduce a seersucker effect, as shown in Fig. 4,
in sections of the web so as to reduce the strong elasticity of the
whole. In an ordinary cotton cloth the seersucker or crinkle effect is
usually produced by the use of a separate warp of heavier yarn than
the rest of the fabric, which warp must be weighted differently and
often a different weave is employed to emphasize the contrast in the
puckered seersucker effect.
In the elastic web all this special preparation is unnecessary.
Wherever the seersucker stripe is desired, strands of rubber are left
out which of course takes away from these portions that element
which contracts the other part of the web, and a seersucker effect is
the result. Such stripes are often used for the ornamentation of some
webs by having narrow sections introduced for border effects, or
running down the center, and in fact they may be employed in a
variety of ways, inasmuch as they lend themselves effectively to
different forms of coloring, in relief to the main fabric.
Fig. 6A.—Harness Draft and Weave for Fig. 6, Simplest Form of Double Cloth
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