Slashdot Mirror


PHP Cookbook

CEHT writes "Like Tony Williams said in his review on PHP and MySQL Web Development: "PHP and MySQL are probably the most pervasive add-ons to Apache web servers across the web". And I agree with him. PHP is a very powerful scripting language, so developers (not just web developers) can do almost anything with it." Read on to see how well CEHT thinks O'Reilly's PHP Cookbook helps you do that almost everything. 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

  1. Strings
  2. Numbers
  3. Dates and Times
  4. Arrays
  5. Variables
  6. Functions
  7. Classes and Objects
  8. Web Basics - available online as example chapter
  9. Forms
  10. Database Access
  11. Web Automation
  12. XML
  13. Regular Expressions
  14. Encryption and Security
  15. Graphics
  16. Internationalization and Localization
  17. Internet Services
  18. Files
  19. Directories
  20. Client-Side PHP
  21. 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.

7 of 238 comments (clear)

  1. PHP Security by leeroybrown · · Score: 5, Interesting

    One thing I would like to see more PHP books do is to cover the various Security problems that are prevalent in many PHP based web applications.

    Don't get me wrong, I find PHP to be the best and friendliest solution for many things, but some of the Security problems could easily be avoided with some common sense security advice.

    1. Re:PHP Security by Albert+Pussyjuice · · Score: 4, Interesting
      You are right - there is a general lack of books which deal with writing very fault tolerant and secure PHP code. Most of the PHP books I've seen in the stores start from the basics and focus on getting a database connection up and running and then doing some simple input/output/db access. I think that while PHP has taken off as a web language, this has hindered development a bit because everyone using PHP keeps running into the same problems and has to recode constantly to work around them.

      Of course, writing secure code isn't specific to a language and any book on writing secure code should help to pave the way to avoid common mistakes, just substitute PHP for language X. For instance Writing Secure Code by Michael Howard could be a good companion book to any programmer's library.

      Hopefully, in a few years PHP will have a large enough installed user base (as I think it already does) that the advances issues such as security, tolerance, etc. will be dealt with in entire book(s). Can you tell I am a PHP afficianado?

      --
      DID YOUR MOM SERVE YOU AN EXTRA HELPING OF DUMB TONIGHT?
  2. Re:More PHP by cyt0plas · · Score: 4, Interesting

    /. itself may not be, but PhpSlash is. Also, I suspect the reason the slashdot crowd likes PHP so much is due to (among other things) a couple of reasons:

    1 - It lets you mix html and code in. Sure, it's not the only language that lets you do it, but it's still a strength.
    2 - It's free, open source (zend crap excluded)
    3 - Microsoft hates it. That's always a plus.
    4 - It's increadibly flexible and forgiving. Coming from a c background, this is one of it's most useful features to me. As far as I can tell, most programmers are inherantly lazy; They don't want to work harder than necessary to do a good job. In PHP, types are incredibly loose. If you want to use a string as a integer, a float, and a string all in the same line, you don't have to cast it. It just does it, and the incredibly vast majority of the time, it does just how you expected it to. Why can't C be that smart?

    --
    Contact Me (got tired of viruses emailing me).
  3. Re:Things PHP is missing by Albert+Pussyjuice · · Score: 1, Interesting

    You bring up some good points but here's a thought I have regarding your first suggestion. Why have a function like SetDBType built in when it can easily be accomplished with a simple include file that specifices the type of database you want to connect to? That way an application only has the database type hardcoded in one place for an entire application. As we can see by C, giving the end programmer a smaller set of tools that always works is better than giving the programmer thousands and thousands of built in functions. I mean, that was the reason for the move to RISC processors after all. Giving everyone these functions that only apply in some situations often just leads to unused functions. Although these types of issues can be more of a problem in a language that is much closer to the hardware.

    --
    DID YOUR MOM SERVE YOU AN EXTRA HELPING OF DUMB TONIGHT?
  4. Don't judge PHP/XML yet, look forward to PHP5. by chregu · · Score: 2, Interesting

    PHP 5 will have much much better XML support.

    There is a lot of work on a complete new DOM extension, which should clean up the mess done in domxml as of PHP 4. It will follow the W3C DOM API as much as possible and is completely rewritten from scratch.

    Furthermore Sterling Hughes is working on SimpleXml. An extension which should make it much easier to access XML Documents with the usual PHP functions.

    The SAX Parser in PHP 5 will also be based on libxml2 and not anymore on the aging expat library.

    XML Validation, XPath and XSLT support are also currently revised and should be improved a lot in PHP5.

  5. Re:The superiority of PHP over Perl by namekuseijin · · Score: 2, Interesting

    >>Recently I've had a chance to do some web design with PHP.

    some (?) web design (??)... how much of it to begin with?

    >>Previously I'd used Perl because I'd heard from many people that Perl was the end all and be all of scripting languages for the web. Imagine my suprise to discover that PHP was vastly superior!

    Perhaps your surprise came from the fact that you were using CGI Perl and that PHP was a fast Apache module? You'd be surprised to learn, though, that today there's also a Perl Apache module as well which is as fast or faster than PHP's...

    >>I know this is a bold statement, but I have solid arguements to support it.

    You better have them as we'll see below...

    >>I'm not arguing that PHP is better than Perl in all cases. There is certainly still a use for Perl.

    Actually, it's the contrary: Perl is one of the most flexible and faster high level languages in existence. It is used for nearly any tasks imaginable dealing mostly with character string processing, that is, it's an overall great general purpose Turing machine. PHP for some misterious reason is used solely as a tool for building html pages, or perhaps PDF using some commercial library...

    Besides, you're aware that php was born from Perl, aren't you? They just dumbed it down so as not to scare ex-M$ users away and because of this the language just lost much of its strengh and flexibility. Ever heard of Perl's motto: "There's more than one way to do it"? It means you can express the same computation many different ways. It means, for instance, that you may express in purely procedural fashion or object oriented, where you see fit. In php (and Python as well) you're trapped in OO craze. There's just one way to do things.

    Also, Perl is one of the most compact (and therefore faster) languages in existence. Of course, people's unwillingness to learn the language make them look at features such as "do { print if /anypattern/; } while();" as beyond their comprehension, but it's not the language's fault if they don't wanna use some the languages builtin features for their great advantage...

    So, i say, i'm not saying Perl is better than php in all cases, there's certainly still a use for php... :)

    >>Finally, I'm not the most talented Perl programmer out there.

    That seems obvious!

    >>I generally prefer to use the vastly superior Python, but can use Perl if I have to.

    I like Python too and highly regard it to be Perl's spiritual brother. But i wouldn't say one or the other is better. Though i would take Perl's flexibility and compactness over Python's rigid OO syntax anyday. One thing is true: they both beat the crap out of php and its VB-like stand...

    >>* Ease of use. I would definitely not recommend anyone new to programming begin with Perl.

    I wouldn't say ease of use is one of Perl's deficiencies. But surely the learning curve for the language is kinda steep. Still, power comes at a price and if you are willing to use a powerful tool you'd better learn how to use it and use it well.

    I can say once you learn Perl right, most other languages just feel like lacking in flexibility, expressiveness or compactness.

    Yes, if you never used a katana, you'd better get to grips first with a bamboo stick or something.

    >> * The OO of PHP is excellent. In my experience, it rivals Smalltalk.

    Who do you think you're fooling? PHP's OO features are more like Javascript than Smalltalk, stop daydreaming. If you want high level OO stuff go with Python's multi-inheritance model.

    >>Hopefully Perl will be patched up so it supports such must-have OO features like introspection, reflection, self-replication and ontological data-points.

    When there's real need for such features, yes. Because Perl doesn't force you into OO syntax, many constructs which just make sense in a purely OO view of the world are not really need

    --
    I don't feel like it...
  6. my god is better than your god by redJag · · Score: 1, Interesting

    it seems to me that most advocates of perl think perl is better than PHP, and vice-versa for PHP advocates.

    The stigma that is associated with perl is generally that "its harder, more lines of code, doesn't have the same functionality" because it takes a steeper learning curve. With PHP you can pretty much do anything right away: just search for the right function. I bet if most big PHP developers gave perl a chance, they'd be surprised.

    Same goes for the other side, however. Since PHP is easy to get started on, there are a lot more PHP newbs than there are perl newbs. This reflects poorly on PHP developers as a whole, which there are obviously some very talented ones that don't deserve said reflection. I think the big thing in PHP is "controlling the beast." It can easily become insecure, inefficient, etc. if you don't know what you're doing..and the abundance of newbs make it appear like this happens all the time.

    Anyway..I just ran outta pennies.. :D