PHP & MySQL: The Missing Manual by Brett McLaughlin
My rating: 3 of 5 stars
This intro to PHP was informative but not as engaging as Head First PHP & MySQL. It's written for those who know HTML, CSS, and some JavaScript. It uses a basic web app as the example project throughout the book, and each section builds on the previous ones. It covers a few PHP best practices, but not as many as I would've liked.
I read this book because as a WordPress web designer, I use PHP to customize WordPress themes and understand how plugins work.
$_REQUEST
is an array that holds data entered into a web form by a user.{}
to use it within a string. This doesn’t work for constants.n
.===
denotes identity, meaning that not only do the two values evaluate to equal values, they are also of the same data type.$_FILES
holds data about a file uploaded by a user.@
directly before a function to suppress errors.->
; the syntax is $object -> method()
.<<<EOD
and end with EOD
(on its own line, with no space before).$_COOKIE
superglobal.$_SESSION
superglobal when dealing with sessions.trim
removes whitespace; rtrim
removes whitespace to the right; ltrim
removes whitespace to the left.preg_match
to test if a regex occurs and preg_match_all
to count all occurrences.require
, not include
, because you need the file to run. Use require_once
unless you truly need to require something multiple times.header
sends a raw HTTP header to the browser. It must be called before any other output. header("Location: path")
changes location to the specified path.is_uploaded_file
ensures that a file name references a file uploaded with HTTP.getimagesize
returns an array of info about an image, including MIME type, height, and width.sprintf
prints to a string. You construct a string using any calculations you need and pass info to sprintf.is_null
tells if something lacks a value.crypt
does one-way encryption.setcookie
sets a cookie.empty
evaluates PHP types and returns true if empty, false if not.session_start
starts a session.$_REQUEST
, $_GET
, and $_POST
in terms of getting request info. So, use the one that will be most clear and specific in a certain case. Use $_POST
when you can, $_GET
when you're getting a GET request, and $_COOKIE
when you're looking for a cookie.