Aimed at beginning PHP developers, this volume uses step-by-step instructions and visual aids to get you started testing scripts, using basic syntax, working with variables, creating Web applications, and other information needed to know to create dynamic Web pages. It covers topics such as Zend Engine, XML support, SQLite, and others.
Larry Ullman is a writer, Web and software developer, trainer, instructor, speaker, and consultant. He has written 23 books and numerous articles. His books have sold over 350,000 copies world wide in more than 20 languages. As his readers, students, and co-workers can attest, Larry’s strength is in Translating Geek into English: converting the technical and arcane into something comprehensible and useful.
This book introduces PHP through well-explained, realistic examples. After exploring the basic concepts and syntax of PHP, it shows how to work with files and databases. It’s not as straightforward as (), but it definitely covers a lot more ground. Each chapter ends with several tips (usually best practices) and suggestions for digging deeper.
Variables � Use print for scalar (single-valued) variables, and print_r() for complex variables (arrays and objects). � Items in single quotes are treated literally; items in double quotes are extrapolated (processed).
HTML Forms and PHP � In forms, pass preset values using input type="hidden". � Use GET to request info from the server; use POST to trigger a server-side action. GET sends info via URL; POST sends it invisibly.
Using Numbers � number_format() rounds and formats.
Using Strings � nl2br() converts newlines to break tags. � htmlentities(), htmlspecialchars(), and strip_tags() make user-provided data safe to print to the browser. � urlencode() encodes a string so it can be passed in a URL. � trim() removes whitespace from the beginning and end of a string.
Control Structures � empty() returns TRUE if a variable has no value, value of 0, or value of FALSE. isset() returns TRUE if a variable has any value, including 0, FALSE, or the empty string. � break exits the current structure. � continue terminates the current iteration of the loop and checks the loop condition again. � exit and die terminate execution. � for loop performs specific statements for a determined number of iterations. � while loop continues as long as the condition is TRUE; most often used to retrieve from a database. � do...while loop is same as while loop, but guarantees that statements are executed at least once.
Using Arrays � foreach loop is used to iterate through an array. � Wrap array constructs in curly brackets to avoid problems with quotation marks. � There are several sorting functions to get by values or keys. Pay attention to maintaining key-value association if necessary. � implode() turns an array into a string. join() is synonymous. � explode() turns a string into an array.
Creating Web Applications � Include files with include(), which warns but continues in case of errors, or require(), which terminates execution in case of errors. Generally avoid include_once() and require_once(), which adversely affect performance. � Constants have unchanging values. Names are uppercase, with no initial $. Assign values with define(). � To test whether a form has been submitted, use if ($_SERVER['REQUEST_METHOD'] == 'POST') {. � header() controls HTTP headers, and can be used to redirect to another page.
Cookies and Sessions � setcookie() sends a cookie. � Delete a cookie by sending a cookie with the cookie’s name and a value of FALSE. � Use cookies when security isn’t a concern, and for < 4 KB of data. Use sessions for more security and more data. � sesion_start() starts a session. � Delete a session with $_SESSION = array(), then session_destroy(). To delete an individual session value, use unset().
Creating Functions � In functions, arguments with default values must come after arguments without default values. � global makes a variable global, usable outside the function. � Put an @ in front of a function to suppress errors, notices, and warnings. � file_put_contents() opens and writes a file. � file() returns file contents as an array.
Files and Directories � Put writable files and directories outside of the Web root directory, for security. � move_uploaded_file() moves an uploaded file from the temp directory. � md5() creates a hash. � fgets() and fgetscsv() read files incrementally.
Intro to Databases � mysqli_query() sends a SQL command to MySQL. � mysqli_connect() opens a connection to MySQL; mysqli_close() closes it. � mysqli_select_db selects the database. � Don’t use die() when a database error occurs; it’s too heavy-handed. � mysqli_real_escape_string() escapes potentially harmful characters. � mysqli_fetch_array() fetches 1 row at a time. � Use TRUNCATE rather than DELETE FROM to empty a table. � mysqli_affected_rows() returns the number of records altered. � Add LIMIT 1 to UPDATE queries to affect only 1 row.
This is an excellent book for PHP beginners. It starts with from complete basics. PHP is a server-side language. This book contains 13 chapters. The Examples in this book are all practical. The last one that is Chapter 13 is the central chapter since you will start building the entire project with the knowledge of all the first 12 chapters. Beginners should definitely buy this book.
Just finished the 21 pages of the introduction (non-counted pages, 481 pages);
Useful note: "within . There you’ll find every script in this book available in a downloadable form."
"PHP came to mean PHP: Hypertext Preprocessor. (The definition basically means that PHP handles data before it becomes HTML)"
"PHP code can be written within your HTML code"
"PHP is designed to do something only after an event occurs—for example, when a user submits a form or goes to a URL (Uniform Resource Locator—the technical term for a Web address)."
"PHP is cross-platform,it enables you to switch your work from one platform to another with few or no modifications."
"With PHP, you can create exciting and original pages based on whatever factors you want to consider. PHP can also interact with databases and files, handle email, and do many other things that HTML alone cannot."
"ASP.NET requires an understanding of VBScript, C#, or another language; and CGI requires Perl (or C). These are more complex languages and are much more difficult to learn."
"This book assumes only a basic knowledge of HTML, although the more comfortable you are handling raw HTML code w/o the aid of WYSIWYG, the easier the transition to using PHP will be. [...] Previous programming experience is not required. However, it may expedite your learning."
-Intro page #16
Oh, how I wish they would take to writing this on the cover of every "how to" computer text. It certainly would save everyone from guessing which book best suits their skill level, and possibly buying a book over their head, under their skill or completely off-topic.
I had to wade through 16 pages of introduction to find this gem, which would be so much more useful to know straightaway, in the bookstore! Alas, I cannot speak on this statement's accuracy... yet! But as my novice PHP brain slowly absorbs it's texty goodness, I will let you know exactly how 'basic' this book assumes I am.
While I am no stranger to PHP, the book offered me a great review of some of the coding language I had forgotten. My only gripe with the book is that for being printed fairly recently, it is lacking the popular OOP (Object Oriented Programing) style of PHP coding. this wasn't that crucial for me (because the web is a great resource), but, when coding, I didn't want to do constant web searches for things that should be included. What would have also made the book so much better is a longer emphasis in MYsql databases - how to use PHP to directly play with the databases. Overall, still a great resource to freshen up on the coding language.
I read half of this book as part of a class, and I'm going to have to admit to myself that I'm probably never going to finish it. That isn't any fault of the book, though! This is a clearly written introduction to PHP and the hands-on exercises really helped it to sink in. I'll definitely keep this around as a reference for any future PHPing.
Great primer on the basics of how to write in PHP. This author has released other books that go beyond what's covered in this book, so non-beginners could probably skip this one and go for those. For beginners, this book explains the concepts and applications of PHP in a way that is very clear and well-paced; I came away fully equipped to build basic PHP/MySQL-powered websites.
If you're just starting out learning PHP, this is the book you should use. I had bought several other PHP/MySQL books, including the one for dummies, and I found this book to be the easiest one to learn from. It covers all the essentials really well: html forms, databases, and the superglobals.
It's really great book for a start. explains each chapter in clear way. one good point: its not one of these books or cources that just explains the syntax, and not how its used in real life.