PHP Cookbook 238
| PHP Cookbook | |
| author | David Sklar and Adam Trachtenberg |
| pages | 608 |
| publisher | O'Reilly |
| rating | 9 |
| reviewer | Edmond Lau |
| ISBN | 1565926811 |
| summary | Solutions and examples for PHP programmers. |
The approach that the authors use in PHP Cookbook is great. Like most computer books, the authors usually include a summary (in sentence forms) to illustrate what the readers will expect in each chapter. Skalar and Trachtenberg take this even further by including some preliminary (code) examples to explain the general ideas behind each chapters. The examples in the book are self-contained. In most cases, I've found examples to exactly fit my needs -- this makes it one of the better reference books.
Each chapter in the book is divided into multiple sections of Problem / Solution / Discussion with a FAQ style. In each case, a simple description of a problem is followed by a PHP script as the solution. But the meat is actually in the discussions: in-depth details are included here, where the authors also include references, extended ideas, and scripts to inform the readers how much more they can do about the issue.
For example, I was going to add a simple script to my website to parse RSS/RDF files from certain news websites (CNN, Slashdot, ...), and use it as my Mozilla homepage. (Who wouldn't?) This script seems to be simple, but I may make a mistake here and there. As reference, I opened up the book to the section "Parsing XML with SAX." Then I realized the authors already had the script to parse RSS/RDF files in the discussion. Bravo!
For myself, the most useful chapters I found are: Web Basics, Forms, Database Access, and XML. There are also good examples in topics such as security, internationalization, and file processing/management. However, this book does not cover the basics of PHP. If you are a good programmer, you should be able to get away with this using the PHP Manual. A good book to learn PHP is Programming PHP, also by O'Reilly.
Although this book covers a wide range of topics, it does not cover topics like generating PDFs. I would also like to see the authors add one (maybe two) case studies in later editions. That would give the reader a more concrete example of how to combine tricks presented by this book. Other than that, at the price of $39.95 (or $61.95 CAD), this book is a great buy!
Topics
- Strings
- Numbers
- Dates and Times
- Arrays
- Variables
- Functions
- Classes and Objects
- Web Basics - available online as example chapter
- Forms
- Database Access
- Web Automation
- XML
- Regular Expressions
- Encryption and Security
- Graphics
- Internationalization and Localization
- Internet Services
- Files
- Directories
- Client-Side PHP
- PEAR
You can purchase the PHP Cookbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Another book with similar title (Score:5, Informative)
Re:PDFs? (Score:3, Informative)
Re:PDFs? (Score:5, Informative)
"An open file format specification, PDF is available to anyone who wants to develop tools to create, view, or manipulate PDF documents."
Re:PDFs? (Score:3, Informative)
No, PDF is open... (Score:5, Informative)
If you're interested in generating PDFs from PHP, there are a myriad of options available by searching Google [google.com]. Some web hosting companies [simpli.biz] also support generating PDFs from PHP, which makes generating PDFs a cinch.
HTH!
Re:PDFs? (Score:3, Informative)
And, yes, it appears to be legal. (It better be, considering I use it at my job.)
Re:YES!!! (Score:5, Informative)
Duck tape was invented during WWII by Johnson+Johnson for the purpose keeping water out of ammunition cases -- it was relatively waterproof, hence the reason people in the military started calling it "duck tape."
You should try watching the History Channel more often.
The perfect companion for this book... (Score:4, Informative)
JP
Re:PDFs? (Score:4, Informative)
Can you generate a PDF with PHP without also generating an Adobe lawsuit?
There's no liability shield built in, but FPDF [fpdf.org] is a great tool that can generate PDFs using PHP without the need for using a commercially-licensed (read "expensive") PDF generating library. I like it because it is distributed under a BSD-like license.
Re:PHP Security (Score:3, Informative)
It's called phpkeychain [sourceforge.net] and it's modelled after the keychain mechanism in OS X.
Re:Things PHP is missing (Score:2, Informative)
http://pear.php.net/
Re:Things PHP is missing (Score:5, Informative)
I believe there is a PEAR package [php.net] that abstracts an OO layer over the functions to various databases. Think DBI for PHP.
2) Native XML support - It's just not there? Why re-invent the wheel each time? Give us a good XML tree-walking engine DAMMIT!
Natvie XML support is there. A SAX parser is usually built in by default. I'm happily using a DOM XML interface that I compiled into my version.
3) sane and consistant functions. Single quotes, double quotes, some functions work with both, some work with one or the other, embedded html in an echo screws up if you don't double quote it, etc.
Quotes in PHP do work in a sane and consistent way, very similar to the way they work in PERL. The only thing I mourn is the lack of a qq[-like facility (and I wouldn't be surprised if someone snuck it in while I wasn't looking, and I just didn't know about it).
4)
Um.... why?
Re:Enough MySQL (Score:3, Informative)
just like PHP
if you want a big, complex, very scalable website; it might be better to go with java, for everything else (>90% of cases, i'm sure) it's easier to do it with PHP.
just the same; if you want a heavy duty database, with lots of concurrent updates, and/or triggers, stored procedures and so... well you can do it with Postgres or mortgage your house and use Oracle. for everything else, it's easier, quicker; and usually faster to use MySQL
Re:Things PHP is missing (Score:2, Informative)
As a side effect, implementing one database call, even with a db_type parameter in the database calls, gives a certain level of abstraction which would allow for greater cross portability. It also helps with application debugging, generating the error closer to the actual failure point, rather than in the wrapper class itself.
Excellent book, I heartily recommend it to any... (Score:4, Informative)
Relevant, real-life useful examples are given and even a seasoned pro like me picked up a few gems like the example user authentication code that utilizes a hash instead of having to go back to the database on each page fetch.
My bookshelves are full of PHP books but most of them are inferior to the online documentation at php.net. They add nothing and are a true waste of trees. This one, however, does not fall into that category.
Re:Ain't php great? (Score:3, Informative)
You obviously don't know Perl, at the very least you don't know about CPAN. How about a decent HTML parser for PHP. XML? How about this: write a program that reads an Excel spreadsheet and uploads its content into a database and let me know how long it takes you in PHP.
PHP sucks because there is no standard way to extend it, and don't mention PEAR as it so poorly documented its almost completely unusable save for a few of the 'modules' that are there.
Rather than implement proper namespaces the developers chose to throw everything in the core language. Thus you get a_function_for_everything() which sure makes it easy for the web monkeys to memorize it or look it up but never how or why something works, and in the end you get nothing more than an unmaintainable mess. What happens when a new feature is needed. Re-write city (Yes that is a rant because I've had live in the shadow of my web-monkey predecessor).
Also what's with mixing data and logic? PHP's whole premise is just plain backwards. Just recently are they trying to bolt on some sort of templating.
Other problems: no access to the web server, difficult to generate web-server response codes. Errors, including full path-names etc are spit out to the user. (great for security).
Its been my experience in dealing with both PHP and Perl that proper, templated, documented code takes about the same amount of time and code. And with all the hacks to work around the above problems with PHP, its just easier and more maintainable to use Perl. (Too bad my employers don't see it that way)
Re:Speaking of FUD (Score:3, Informative)
Remember, PHP is to ASP as Zend is to VBScript.
Re:Sick and tired of this (Score:1, Informative)
Re:Ain't php great? (Score:4, Informative)
If that is a challenge, then I accept. I can guarantee you that for every command in PHP, there is an equivalent command (or module) in Perl. Hence you should be able to write this imaginary program in exactly the same number of lines...
Have a look at Embperl, HTML::Mason, Apache::ASP for a couple of examples of how to do this. Most people who knock perl have never discovered the right tools. Personally I would never use those tools, because I am a strong believer in the separation of Code and HTML. I use a templating system for all my projects, and you will never see one HTML tag in my code. Once you work with a team of developers and a separate team of designers you will understand the need for this separation.
PHP is a great tool! I have used it for several applications in the past (6 or 7 years ago). But if you think that PHP can do more than perl can then you are mistaken...
Re:The superiority of PHP over Perl (Score:4, Informative)
I did a lot of Perl development before switching to PHP, and some of the things you mention that are missing from Perl are readily available as modules from CPAN [slashdot.org]. But that just adds another point in PHP's favour -- the default install comes with all the stuff you mentioned.
Before anyone gets their Perl backs up, let me point out why a good default install is important for web development: you don't always have control over the server, so you can't always get the Perl modules you want. (But if you want to re-write your code, sometimes, you'll get what you need! (Couldn't resist.))
Re:Hmm (Score:2, Informative)
An entire chapter [php.net] in the manual for it.
Re:Speaking of FUD (Score:5, Informative)
You have that ass-backwards. PHP is the language, Zend, the engine. Any other scripting language could be developed and used with the Zend engine.
Definitely Worth the Buy (Score:2, Informative)
Re:The superiority of PHP over Perl (Score:1, Informative)
2. who in their right mind would *want* to mix html with their code? When I was handed a vendor's solution with php + html mixed in a single file the first
thing I did was separate the two. How the hell can you see what is going on?
3. so much of php looks like it was lifted right from perl.
4. the real die hards are on a crusade to re-write the whole world in php. gotta laugh.
5. how come just about every site, every book on php is geared towards amatuers? I can never find any depth. Even the manual on php.net has big holes in it.
6. why are there 4 versions of the split function?
7. as for all options being compiled in, they aren't. Did you ever try to build php for the first time? You'll spend hours trying to figure out which options you should include.
Obligatory Smarty plug (Score:3, Informative)
I thought that PHP did a great job of mixing HTML and code until my PHP apps started reaching a certain size. Even using function calls and classes, templates started getting convoluted. Then I discovered Smarty [php.net] and my whole way of working changed. Smarty is a template manager that allows for more precise separation of content and code. As a super-simple example, lines like become {$variable}. Over the course of a whole site, the savings from this syntax alone ease code readability (yes i care about such a thing). But there's a lot more to smarty than shorter variables, including shorthand for string modifiers and loops, as well as a nifty caching system that can speed up dynamically generated sites, and zillions of other really cool things for "lazy" programmers like me.
A lot of people on this thread have mentioned AdoDB (my other favorite PHP add-on), but I haven't seen anyone give a proper shout out to Smarty. It's made my life easier.