×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

PHP Cookbook

timothy posted more than 10 years ago | from the stir-it-up dept.

PHP 238

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.

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.

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

238 comments

FIRST LINUX HATER POST!!! (-1, Troll)

Anonymous Coward | more than 10 years ago | (#6151077)

Take a shower and move out of your parents basement! Maybe someday if you scrub the grease off your face you could actually go on a date!!

second post! (-1, Offtopic)

Autolycus (151640) | more than 10 years ago | (#6151095)

second post!

Student Suspended Over Suspected Use of PHP (3, Funny)

Anonymous Coward | more than 10 years ago | (#6151149)

Topeka, KS - High school sophomore Brett Tyson was suspended today after teachers learned he may be using PHP.

"A teacher overheard him say that he was using PHP, and as part of our Zero-Tolerance policy against drug use, he was immediately suspended. No questions asked," said Principal Clyde Thurlow. "We're not quite sure what PHP is, but we suspect it may be a derivative of PCP, or maybe a new designer drug like GHB."

Parents are frightened by the discovery of this new menace in their children's school, and are demanding the school do something. "We heard that he found out about PHP at school on the internet. There may even be a PHP web ring operating on school grounds," said irate parent Carol Blessing. "School is supposed to be teaching our kids how to read and write. Not about dangerous drugs like PHP."

In response to parental demands the school has reconfigured its internet WatchDog software to block access to all internet sites mentioning PHP. Officials say this should prevent any other students from falling prey like Brett Tyson did. They have also stepped up locker searches and brought in drug sniffing dogs.

Interviews with students suggested that PHP use is wide spread around the school, but is particularly concentrated in the geeky nerd population. When contacted by BBspot.com, Brett Tyson said, "I don't know what the hell is going on dude, but this suspension gives me more time for fraggin'. Yee haw!"

PHP is a hypertext preprocessor, which sounds very dangerous. It is believed that many users started by using Perl and moved on to the more powerful PHP. For more information on how to recognize if your child may be using PHP please visit http://www.php.net.

Re:Student Suspended Over Suspected Use of PHP (-1, Offtopic)

Tukz (664339) | more than 10 years ago | (#6151226)

i can only find one word to describe that.

ROFLMAO!!!!!!!!

Re:Student Suspended Over Suspected Use of PHP (0)

Anonymous Coward | more than 10 years ago | (#6151491)

Feel free to actually link back to bbspot (http://bbspot.com/ [bbspot.com]) next time

third post! (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6151157)

third post!

Best of all (1)

gazbo (517111) | more than 10 years ago | (#6151097)

Linux comes with a php2asp utility, so that you can write scripts in your favorite language, then have it automatically turned into ASP for running on the WinDOS boxes that your boss bought (PHBs just love their FUD ;-)

Speaking of FUD (0, Flamebait)

poptones (653660) | more than 10 years ago | (#6151364)

ASP is not a language. PHP is a language (I'm being generous here). BASIC is a language. Java is a language. Javascript is a language.

Speaking as someone who has worked with both, php2asp is about as useful as those "pascal2c" tools that were so common a decade ago. It works in only the simplest of cases, and rarely supports the internal objects supported by most ASP languages (ie vbscript and jscript).

PHP blows chunks. It's too bad such a shitty little "language" has taken on such proportion simply because it was, for a while, the only "better" alternative on linux/apache to perl (an even shittier, even more cryptic little language).

Since the "language of browsers" is ECMAscript it makes sense to use that on the server, too, so one doesn't have to constantly shift back and forth between languages. And one doesn't HAVE to use an MS product in order to do so. It's really too bad so many otherwise intelligent folk abide the braindead notion that ECMA(java)script = ASP = MS.

Re:Speaking of FUD (2, Insightful)

lamz (60321) | more than 10 years ago | (#6151448)

Since the "language of browsers" is ECMAscript it makes sense to use that on the server, too, so one doesn't have to constantly shift back and forth between languages.

That doesn't even remotely make sense. Most browsers have javascript built-in, so that should decide what language to use server-side? Personally, keeping javascript for client-side and PHP or whatever for server-side is less confusing. That contextual switch is easier when the client-side / server-side code looks different.

Now I'm off to find a review of a Javascript book, so that I can insert random comments about what a shitty little language it is. That will be quite helpful for someone who wants a book about Javascript, I'm sure.

Re:Speaking of FUD (2, Informative)

runderwo (609077) | more than 10 years ago | (#6151514)

ASP is not a language. PHP is a language (I'm being generous here).
PHP actually is not a language. PHP is an engine for embedded scripting languages in markup documents. Zend is the scripting language that most people generalize as "PHP", but any other scripting language could also be developed and used with the PHP engine.

Remember, PHP is to ASP as Zend is to VBScript.

Re:Speaking of FUD (4, Informative)

lamz (60321) | more than 10 years ago | (#6151642)

PHP actually is not a language. PHP is an engine for embedded scripting languages in markup documents. Zend is the scripting language that most people generalize as "PHP", but any other scripting language could also be developed and used with the PHP engine.

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.

Re:Speaking of FUD (4, Insightful)

Publicus (415536) | more than 10 years ago | (#6151569)

So what are you saying is better than PHP? Running ASP with Javascript (or ECMAscript to be pedantic)?

If you can tell me that handling forms and working with databases can be done better with something other than PHP please do.

Also, please tell us what is a 'bigger' language, if PHP and *gasp* Perl are so little?

I wonder because I started in ASP with VBScript. I learned Perl and PHP and now I do PHP pretty much full time. If I want a script that is blantent CGI I use Perl. To me PHP and Perl completely blow away (not blow chunks) ASP with VBScript -- they are far better languages for web development. I can't say exactly why I think that, but one of the main things for me is the quality of the community surrounding the language. There's a lot more user support for PHP and Perl which to me is more helpful than the MSDN library will ever be. I also like a lot of punctuation -- but that's just a personal preference.

As far as switching back and forth between languages (JavaScript and PHP, for example), I never thought it was so silly. To me, doing things client-side is distinctly different from doing things server-side. It's no problem to have different languages for those two things. Especially when have to limit what you do on the client side because every browser is different. It seems to me like wasted effort to spend to much time on JavaScript stuff, because lo and behold browser X won't support what I'm trying to do. If I do it server side in PHP, I have an easier time writing portable code.

You certainly have a right to advocate your language of choice, and probably a right to bash others, but could you explain yourself a little better?

Re:Speaking of FUD (1)

lamz (60321) | more than 10 years ago | (#6151725)

I wonder because I started in ASP with VBScript. I learned Perl and PHP and now I do PHP pretty much full time.

I followed pretty much the same path as you, and once I tried PHP there was no turning back, especially once I discoverd the Smarty Template Engine [php.net]. Everyone doing PHP development should check it out.

PDFs? (1, Troll)

Mr Guy (547690) | more than 10 years ago | (#6151115)

it does not cover topics like generating PDFs

Isn't PDF a closed format? Can you generate a PDF with PHP without also generating an Adobe lawsuit?

Re:PDFs? (2, Informative)

Mr Guy (547690) | more than 10 years ago | (#6151147)

Also, someone could bring this [sourceforge.net] up, but I'd still like an answer. Isn't PDF owned by Adobe?

Re:PDFs? (0)

Anonymous Coward | more than 10 years ago | (#6151355)

Good point, and isn't TXT owned by Microsoft - it is notepad.exe's native file format.

Re:PDFs? (5, Informative)

Anonymous Coward | more than 10 years ago | (#6151173)

From the adobe website:
"An open file format specification, PDF is available to anyone who wants to develop tools to create, view, or manipulate PDF documents."

Re:PDFs? (0)

Anonymous Coward | more than 10 years ago | (#6151180)

You can only generate a PDF lawsuit from PHP by using the --lawsuit tag!

Re:PDFs? (1)

Christianfreak (100697) | more than 10 years ago | (#6151184)

PDF is an open format. There are tons of ways to generate a PDF on a unix system.

*Obligatory PHP flame from the Perl Guy *
Of course unlike Perl there are no easy/good ways to create one in PHP
*/Obligatory PHP flame from the Perl Guy*

All PDF generators suck (2, Insightful)

Black Perl (12686) | more than 10 years ago | (#6151541)

*Obligatory PHP flame from the Perl Guy *
Of course unlike Perl there are no easy/good ways to create one in PHP
*/Obligatory PHP flame from the Perl Guy*


There are no good ways to create one in any language. Current solutions are either:

(1) A thin shell over text and graphics primitives

or (2) dependent on an external rendering engine which creates another format like Postscript.

I'd like a high-level PDF creation library that would let me, say, directly create a table that is sized to fit the contents like HTML, but unlike HTML, will split the table across multiple pages, repeating header and footer information. Sounds straightforward, right? Not possible now. I've checked with Adobe engineers, and it's not even possible with their $20K PDF generation toolkit.

I can just hear the XSL-FO people saying, "but it IS possible with XSL-FO." And it's also possible, given all the sand and steel you could possibly need, to build a window. Point is, it's currently way too much trouble. I'm sure it'll get there eventually, but PDF creation is really an idea in its infancy right now.

Re:PDFs? (3, Informative)

Anonymous Coward | more than 10 years ago | (#6151198)

Here's what I use http://www.fpdf.org/ [fpdf.org] It's a steep learning curve, but it works

No, PDF is open... (4, Informative)

SlashChick (544252) | more than 10 years ago | (#6151201)

The actual document specification for PDF is open. Adobe just happened to not only create the format, but also make the most popular PDF reader and writer (the Acrobat series.) There are, however, free alternatives such as Ghostscript that generate great PDFs from a Postscript file (which you can generate from any program in Windows just by checking the "Print to File" box on a Postscript printer.)

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? (3, Informative)

holovaty (678950) | more than 10 years ago | (#6151229)

Yes, it's completely possible, as long as your version of PHP has pdflib [http://pdflib.com/] installed as a module or compiled in.

And, yes, it appears to be legal. (It better be, considering I use it at my job.)

Re:PDFs? (1)

chickerino (540140) | more than 10 years ago | (#6151248)

you can use PDFLib : http://www.pdflib.com/ but it's pretty ugly.

the nicer solution would be to use XML-FO but I'm not sure what the PHP support is like.

Re:PDFs? (3, Informative)

Kamel Jockey (409856) | more than 10 years ago | (#6151418)

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.

Get some of this... (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6151122)

Get a little goatse [goatse.cx] in ya on this gloomy Monday morning.

PHP Security (5, Interesting)

leeroybrown (624767) | more than 10 years ago | (#6151126)

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.

Re:PHP Security (4, Interesting)

Albert Pussyjuice (675113) | more than 10 years ago | (#6151330)

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 [amazon.com] 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?

Re:PHP Security (4, Insightful)

cyt0plas (629631) | more than 10 years ago | (#6151340)

The security problems usually aren't the problems of php, it's the developer's problems. PHP is one of the most newbie friendly web development languages out there. For heaven's sake, it even escapes user inputted strings FOR YOU. That stops most sql exploits, shell string exploits at the door. What happens is that some newbie who hasn't taken the time to read the documentation does something dumb like include($_GET['filename']); While this is a exploitable situation, how many CGIs have been exploited because the author failed to strip/escape user input?

PHP has a couple of common mistakes, but I'm far more apt to trust an inexperienced PHP programmer over an inexperienced Perl programmer, as far as secure code goes.

Re:PHP Security (1)

jpkunst (612360) | more than 10 years ago | (#6151420)

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.

I completely agree with you. David Sklar (one of the authors of the book reviewed here) gave a very interesting presentation about the subject of security in web applications at the International PHP Conference (May 2003) in Amsterdam. You can view the slides of his talk here [php.net].

JP

Re:PHP Security (2, Informative)

ikewillis (586793) | more than 10 years ago | (#6151462)

I'm working on a project that aims to solve the matter of keeping database access passwords secure when using PHP as an Apache module (and consequently all PHP scripts must be readable by a single user)

It's called phpkeychain [sourceforge.net] and it's modelled after the keychain mechanism in OS X.

w00t (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6151128)

natalie pr0tman and h0t gr1tz...

greetz to da 254-hi klan

YES!!! (4, Funny)

SuperDuG (134989) | more than 10 years ago | (#6151129)

Please continue to make these books, I would love to "quit passing on my knowledge" to the morons around me!!

In all seriousness I enjoy PHP because it is pretty self explanatory, and it can use plain old html inside it too. It's just nice to use a scripting language for the web that was made for webpages originally, not a language that was created for ...

... does anyone really know the original intent of perl? I guess that's like trying to find the oringal intent for ducK tape (and no, don't say to seal off ventilation ducts, coz that's what they'd have you believe.)?

Re:YES!!! (0)

Anonymous Coward | more than 10 years ago | (#6151188)

... does anyone really know the original intent of perl?
Archaeological investigation into recreating the language of the Old Ones with a view to raising Ktulu from R'yleh and the bringing of the End Times.

Re:YES!!! (0)

Anonymous Coward | more than 10 years ago | (#6151207)

> ... does anyone really know the original intent of perl?

Yes, to make doing things that admins did very day easier/automated.

Re:YES!!! (2, Funny)

maharg (182366) | more than 10 years ago | (#6151238)

Practical Extraction and Report Language

OR

Pathologically Electic Rubbish Lister

Re:YES!!! (4, Informative)

Surak (18578) | more than 10 years ago | (#6151296)

... does anyone really know the original intent of perl? I guess that's like trying to find the oringal intent for ducK tape (and no, don't say to seal off ventilation ducts, coz that's what they'd have you believe.)?

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. ;)

Re:YES!!! (1)

SuperDuG (134989) | more than 10 years ago | (#6151422)

Okay I really wasn't expecting a correct answer there. I don't know which is worse, the fact I knew that ... or the fact someone other than me watches the history channel that much.

Re:YES!!! (1)

Surak (18578) | more than 10 years ago | (#6151535)

Hey, HC it beats the hell out of the rest of the crap on TV most days of the week. ;)

Re:YES!!! (1)

Christianfreak (100697) | more than 10 years ago | (#6151373)

... does anyone really know the original intent of perl?

To manipulate text. Funny since everything is going to a text/XML type of meta format Perl is very well suited to the Web and to system management or for small GUI programs. I think Perl would be a great replacement for say VB.

*Obligatory PHP flame from the Perl guy*
of course Perl can do all that and it doesn't need_a_function_for_everything() to accomplish it either.
*/Obligatory PHP flame from the Perl guy*

Re:YES!!! (1)

Mr Bill (21249) | more than 10 years ago | (#6151384)

Perl has its roots as a tool combining the virtues of sed and awk, and was started mainly as a text parsing/processing language. This is one of the many reasons why it is so good as a web development language.

What seems to scare people about perl is that there as so many different ways that you can tackle a job like building dynamic web sites. Perl on it's own doesn't forcefeed anything to you, it lets you find your own style. Many people who start with perl will try to do everything from scratch instead of finding one of the many development environments that simplify things for you a clean framework for developing web applications. Some examples are Axkit, HTML::Mason, Template Toolkit, Embperl, Apache::ASP, CGI::Application, Apache::PageKit, and many more.

Anyway, this article is about PHP, and I won't knock it just because I'm a perl developer. I actually used PHP quite heavily back in 96 when version 2 was just coming out. It was a fantastic tool (even back then) and really let me cut my teeth on dynamic web development. However, I have wandered over to the perl camp, because it is a better tool for me.

Original Purpose (0)

Anonymous Coward | more than 10 years ago | (#6151668)

Original purpose of duck tape: sealing amo cases in WWII. Check out www.straightdope.com for the details.

Enough MySQL (-1, Flamebait)

ShieldW0lf (601553) | more than 10 years ago | (#6151134)

Why is MySQL mentioned in every article on PHP to cross the forum? Get a real database.

Re:Enough MySQL (2, Informative)

Kz (4332) | more than 10 years ago | (#6151483)

Because it's easy, fast, and 'real' enough for the vast majority of quick webpages.

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

The superiority of PHP over Perl (-1, Interesting)

Anonymous Coward | more than 10 years ago | (#6151136)

Recently I've had a chance to do some web design with PHP. 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! I know this is a bold statement, but I have solid arguements to support it.

Before I begin, let me just clarify something. I'm not arguing that PHP is better than Perl in all cases. There is certainly still a use for Perl. Also, PHP isn't perfect but it does manage to fix many of the shortcomings I've had with Perl. Here are a few of the things I've noticed about PHP. Finally, I'm not the most talented Perl programmer out there. I generally prefer to use the vastly superior Python, but can use Perl if I have to.

  • Ease of use. After about a day I had an excellent understanding of both PHP and SQL. I was able to get a stable, useable and presentable website up within 24 hours of reading the basics of PHP. Learning Perl took me weeks and I'm still not even as good with it as I am with PHP. I would definitely not recommend anyone new to programming begin with Perl.
  • The OO of PHP is excellent. In my experience, it rivals Smalltalk. We all know that Perl's OO still needs work (whether or not OO is all that great is another discussion.) Hopefully Perl will be patched up so it supports such must-have OO features like introspection, reflection, self-replication and ontological data-points.
  • Outstanding database support. PHP supports virtually every DB under the sun (although Berkeley DB is missing, oddly enough.) Perl seems limited to MySQL and PostgreSQL, and its really a kludge for the later. I've heard that this will be fixed in upcoming versions of Perl though.
  • Speed. PHP is one of the fastest languages I've ever used. While it won't be replacing assembly or C, its definitely faster than Perl in almost every case, particularly in regex which has long been Perl's strongest point. I'm sure there are cases where Perl is equal to PHP, but I can't think of any at the moment.
  • Portability. I can take PHP code off my Linux box and plop it onto an IIS server, or even one of those new Macintosh servers and have it run without having to change a single line of code. Try doing this with Perl! Its as though it was written in assembly, Perl requires that much rewriting.
  • Graphics. PHP comes with a nice little graphics library. While I wouldn't use its to code the new Doom (VB would be a better choice) its adequate for most web pages, and should be considered as a substitute for Flash for certain things. Perl lacks a graphics library of any kind.
  • Data Structures. Under PHP you can create any type of datastructure you need: Linked lists, binary trees, hash tables, queues, inverse Reiser-biased recursion trees, etc. Under Perl you're extremely limited in what you can do. This is because Perl isn't OO (so you can't create Node classes, for example, usefull in a linked list) and because it lacks pointers. Some of you may notice that PHP lacks pointers, but look deeper! Behind the scenes, hidden from the user pointers are used. Because of this, PHP can support complex data structures.
Again this is just my experience. I don't mean to offend any Perl coders because Perl was an excellent language. However, in certain cases it may behoove one to write the back end in PHP instead of Perl.

Re:The superiority of PHP over Perl (3, Informative)

lamz (60321) | more than 10 years ago | (#6151562)

Amen!

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.))

More PHP (1)

betis70 (525817) | more than 10 years ago | (#6151138)

You would think slashdot was written in PHP, considering the amount of coverage it gets in the book reviews.

Re:More PHP (4, Interesting)

cyt0plas (629631) | more than 10 years ago | (#6151245)

/. itself may not be, but PhpSlash [sourceforge.net] 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?

Re:More PHP (1)

Ron Harwood (136613) | more than 10 years ago | (#6151703)

I'm sure that if PHP had been more mature when /. was created - it would have been considered. If PHP of today were available when Taco was considering it - I'm sure that it would be a different beast today.

But consider the number of man hours that are in the slash code... it works... it does what they want... and it's in a language that they know well. There's no reason to ever change it.

Another book with similar title (5, Informative)

bloxnet (637785) | more than 10 years ago | (#6151139)

Not to be confused with "PHP Developer's Cookbook" (ISBN: 0672323257 - Publisher: Pearson Education) which is a very well regarded reference for PHP. Just wanted to avoid confusion and suggest the book at the same time. There seems to be a flood of PHP/MySQL books out there, or people are just getting around to reviewing them....not sure.

Re:Another book with similar title (1)

goph (669787) | more than 10 years ago | (#6151222)

well ofcourse, since they switched from Perl to PHP they have twice as much time left to write a review!! isn't it fantastic mike?!

Oh my god! (-1)

Anonymous Coward | more than 10 years ago | (#6151596)

Oh my god! It's a cookbook! The PHP Cookbook is a cookbook! *runs around flailing arms*

Ain't php great? (1)

cyt0plas (629631) | more than 10 years ago | (#6151165)

As a web developer, php has been a real life saver.

It would take a whole lot of perl code to achieve the same functionality that can be accomplished in 200 well-written php code. (Depending on what it did - it's based off my personal experiences).

In addition, the ability to mix and match html/php on a cross-platform programming language, as well as write scripts that also run on the command line is worth it's weight in gold (note to people who don't understand that saying, it's really valuable to me). Although perl and cgi scripts can be ran from the command line, they can't have (X)HTML mixed in quite as easily.

Re:Ain't php great? (0)

Anonymous Coward | more than 10 years ago | (#6151218)

In my experience, it takes about 100 lines of perl code to acheive the 200 PHP. But I prefer python anyway...

Mixing perl+html. Been done. Embperl.

Re:Ain't php great? (2, Informative)

Christianfreak (100697) | more than 10 years ago | (#6151508)

It would take a whole lot of perl code to achieve the same functionality that can be accomplished in 200 well-written php code.

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:Ain't php great? (3, Informative)

Mr Bill (21249) | more than 10 years ago | (#6151526)

It would take a whole lot of perl code to achieve the same functionality that can be accomplished in 200 well-written php code. (Depending on what it did - it's based off my personal experiences).

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...

Although perl and cgi scripts can be ran from the command line, they can't have (X)HTML mixed in quite as easily.

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...

Buy a Book v.s Web Resources (5, Insightful)

leeroybrown (624767) | more than 10 years ago | (#6151192)

I've been doing PHP web development on and off for a couple of years now and I've always found that it's greatest strength has been the availability of very god online resources.

PHP.net [php.net] and many other excellent resources are only a browser click away and remain up to date for free. PHP is one of those areas where I'll save my money and buy a book I'll get genuine reference use from.

Re:Buy a Book v.s Web Resources (2, Insightful)

elmegil (12001) | more than 10 years ago | (#6151714)

Nothing like having half a dozen browser windows/tabs open at the same time, trying to fix/write your web page app. Give me a book any time, realspace makes it a lot more convenient to arrange references around me, IMNSHO. That said, I do appreciate the web references, they're good backfill when nothing else seems to solve the problem. Most of the time. Sometimes googling for answers is like finding a needle in a haystack.

Not another one (-1, Offtopic)

tmark (230091) | more than 10 years ago | (#6151195)

Am I the only one who is sick of seeing reviews of PHP and MySQL books ? How many is enough ? Are there that many people clicking through the bn.com affiliate links when a review is posted here ?

PHP most pervasive? PERL (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6151220)

I guess for web development. I like doing everything in PERL. Might have something to do with not knowing php. ;P
sub usual_slashdot_activity;

while ($phpzealots eq "annoyed"){
utter(meaningless_nonsense);
}

Re:PHP most pervasive? PERL (1)

cyt0plas (629631) | more than 10 years ago | (#6151362)

function usual_slashdot_activity () {
while ($phpzealots == "annoyed") {
utter($meaningless_nonsense);
}
}

That wasn't so hard, was it?

Kiss and say goodbye to Java language!! (0, Troll)

Anonymous Coward | more than 10 years ago | (#6151223)

No Java, no JSP man. Simply use PHP for web development.
Forget Java man and go to PHP!

PHP is 4 times faster than Java technology 'JSP' (Java server pages).

This tallies because compiled "C" program is 4 times faster than Java.

Moreover, PHP is getting the object oriented features of Java language.

The real usefulness of Java is 'Java applets' which run on client browsers but on the server side you simply use PHP.

PHP is a very lightening fast object oriented scripting language. PHP is 100% written in "C" and there is no virtual machine as in Java. Nothing can beat "C" language ("C" is a language which never dies!!)

(Java is just another language. The PHP project needs millions of Java programmers who can add the Java's language features like inner classes, static, private, protected and others to PHP. PHP already has some of java' features).
Java programmers will really "LOVE" PHP as PHP class is identical to Java's class keyword.

Read the benchmars of Java JSP and PHP. PHP tops in the speed!!

Read the doc here [linuxdoc.org] and mirrors at [1] [redhat.com], [2] [ucla.edu], [3] [gatech.edu], [4] [caldera.com].

Re:Kiss and say goodbye to Java language!! (1)

cyt0plas (629631) | more than 10 years ago | (#6151390)

Then use the Alternative PHP Cache [communityconnect.com], and get that speed up another 25-400% (depending on the size and complexity of your program. Eat that, java.

PHP = Pretty Hard Penis (-1, Troll)

Anonymous Coward | more than 10 years ago | (#6151225)

Sounds like a great book, but it's missing a few things. First, when using my PHP, I find that I need to use my hand to direct it to a waiting female's vaginal opening. (Caution must be used to avoid the anus.) However, the female's hand may also be used. Although this may sound strange to amateur PHP users, it is actually much more efficient.

Second, after sex my PHP turns to a PLP (pretty limp penis). To revive it, I simply wait a few minutes and then stroke gently, adding a females mouth or hand when necessary.

These tips, while basic, should really be included in this book. Other than that, I give it two heads up!!

The Cookbooks are wonderful! (2, Insightful)

Utoxin (26011) | more than 10 years ago | (#6151241)

I've got the Perl cookbook, and have used many of the source code samples found inside in my work. However, most of the development I do is PHP, and I'm extremely excited to hear that they've released a cookbook for PHP. I reccomend this and the Perl cookbook to any developer who wants advice or inspiration.

Things PHP is missing (4, Insightful)

Anonymous Coward | more than 10 years ago | (#6151274)

1) consistant database integration - Why not have a SetDBType() function, rather than hardcoding mysql_connect, mssql_connect, myodbc_connect, pgqsl_connect, etc?

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!

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.

4) .NET support?

In short, PHP is a good language for small projects, but just doesn't cut it in an enterprise setting.

Re:Things PHP is missing (1, Interesting)

Albert Pussyjuice (675113) | more than 10 years ago | (#6151394)

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.

Re:Things PHP is missing (2, Informative)

Angry White Guy (521337) | more than 10 years ago | (#6151486)

It's also on the query side as well. How many people have written wrapper classes to deal with different databases?

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.

Re:Things PHP is missing (2, Informative)

tkiehne (473468) | more than 10 years ago | (#6151477)

The PEAR packages, usually bundled with the distribution, would take care of the first two:
http://pear.php.net/

Re:Things PHP is missing (4, Informative)

weston (16146) | more than 10 years ago | (#6151479)

1) consistant database integration - Why not have a SetDBType() function, rather than hardcoding mysql_connect, mssql_connect, myodbc_connect, pgqsl_connect, etc?

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) .NET support?

Um.... why?

.NET support in PHP. Why? (0)

torpor (458) | more than 10 years ago | (#6151563)

Because the poster is an M$ Troll, of course...

There is no good reason for PHP to support .NET other than to be qualified for "embracing" and "extending'"...

PHP/MySQL and Apache is what .NET is designed to get rid of...

Re:Things PHP is missing (1)

Gaza (3339) | more than 10 years ago | (#6151490)

For the consistant database integration, take a look at the Pear Database class that is included in every PHP download. http://pear.php.net/manual/en/package.database.php

They abstract out all the database related functions, and are a pleasure to use.

Re:Things PHP is missing (1)

joeldg (518249) | more than 10 years ago | (#6151560)

dude..
native XML support, it is enabled by default. (see http://us4.php.net/manual/en/ref.xml.php)
.NET is really only useful/meaningful in MS licenced environment.
If you want database integration, there are 50 packages you can download (not including PEAR) which can handle all of that for you.
consistent functions? give me a break. single/double quotes? if you having problems with those in php then you have a long way to go before using the language for anything practical.
Granted, I have seen some (array functions in php) which could use a little bit of work on getting them more consistent, but overall things are worlds ahead of asp (which I can say as I used to actually be an asp developer, three years ago before I discovered php and switched everything to linux)

You aren't looking in the right places. (1)

SlashChick (544252) | more than 10 years ago | (#6151574)

I'm pretty sure this is a troll (I mean, .NET support?), but since it's had a large amount of "Insightful" mods, I figured I would point out at least one misconception.

The parent poster complains about "consistant (sp) database integration" as one of the main problems with PHP. This is usually a problem noted only by those who haven't used PHP in serious development. Sure, if you're writing a 20-line script that you know is only going to use MySQL, then who cares what database connection statements you're using. However, if you're writing anything that needs to be more serious and portable, check out one of PHP's database abstraction libraries: ADOdb [weblogs.com] or Pear DB. [php.net] Both of these libraries will let you abstract out database functions so that they aren't tied to one specific database.

Personally, I prefer ADOdb. Not only is it faster than Pear DB, but there's also a C port to speed it up even more. ADOdb also has more capabilities, and its author hangs out in their forums and is extremely helpful with user questions.

You have to change your mindset a bit to code with ADOdb or Pear DB, but it's worth the bit of extra learning curve to gain portability. Since ADOdb can generate insert/update SQL and also generate HTML tables, I find that I'm faster coding with it than I ever was with mysql_query()... and I can switch to Postgres or Microsoft SQL Server at any time without really thinking about my database code.

I hope this helps those of you who are still stuck with mysql_query() or similar. <plug>Also, we're a web hosting company [simpli.biz] that supports PHP 4.3.x, ADOdb and Pear DB, and we will answer your PHP questions as part of your web hosting package.</plug>

Re:You aren't looking in the right places. (1)

joeldg (518249) | more than 10 years ago | (#6151625)

given the benchmarks at http://phplens.com/lens/adodb/ straight mysql is still faster.
though I can see this as a boon to developers coming the microsoft side of things and trying to get asp code ported to php.

php, replaces perl for me. (1)

joeldg (518249) | more than 10 years ago | (#6151275)

I use it for just about everything these days over perl. Spam filters, graphing, smtp server, ncurses frontends for apps, fractals, you name it. I also post a lot of what I do in it on my site: http://lucifer.intercosmos.net/

Come on now.... (0)

botzi (673768) | more than 10 years ago | (#6151306)

...we all know the real reason [attrition.org] a lot of people prefer PHP over Perl;o))))))

Re:Come on now.... (1)

joeldg (518249) | more than 10 years ago | (#6151396)

okay okay.. you got me.. (and yea, that was my background image for a while... mmmm background image)

Sick and tired of this (2, Insightful)

aardwolf204 (630780) | more than 10 years ago | (#6151298)

<rant>
I'm a PHP/MySQL junkie, and every time I see anything about PHP on /. its a damn book review. I know the dynamic duo (php/mysql) are the hottest things to hit the net since <blink> but could we get some more interesting new on php, how about something on php-gtk, or the various other php related projects.
</rant>

Re:Sick and tired of this (1)

joeldg (518249) | more than 10 years ago | (#6151442)

you could (see /. navigation) "submit story" on something (i.e PHP/GTK) or write an article about PHP5 implementation and new features and submit it..
I helped out on the PHP-ncurses stuff (see zend.com in tutorials) and submitted that, but it was rejected.. I believe it was passed over in favor of a PHP book review (professional PHP or whatever).. but worth a shot.

Re:Sick and tired of this (1, Informative)

Anonymous Coward | more than 10 years ago | (#6151519)

I've never read a decent book on PHP, tho the manual is superb for basic stuff. I also want a book that covers things not so well documented online, that I'd otherwise have to grep the source files to learn. MCAL, MCRYPT, Berkley DB extensions etc are not covered well in the online manual. Yeah some advanced GD, curses and PHP-Gtk stuff would rock too.

Good learning tool (2, Insightful)

mni12 (451821) | more than 10 years ago | (#6151311)

I actually bought a copy of this book, as well as the other one referenced in this review. I found them quite useful in learning PHP - the examples can be easily tweaked to create useful little applications. I haven't done very much with web programming except for few CGI-scripts and PHP definitely looks much easier way to create useful applications.

The examples of integrating to MySQL were especially useful as I have been playing with Microsoft Access using MySQL as server, and now I can easily create web views from the database!

Hmm (1)

JanusFury (452699) | more than 10 years ago | (#6151327)

What I want to know is if there's any way to do any sort of Reflection in PHP. I'd buy this book if it had anything on that subject. JSP, ASP.net, and ASP all have Reflection or at least some features similar to it, but PHP seems to have nothing of the type... and there are some types of code that are next to impossible to write without Reflection - things like XML serialization/deserialization in particular are a pain without it.

The perfect companion for this book... (3, Informative)

jpkunst (612360) | more than 10 years ago | (#6151339)

... is (IMHO) the MySQL Cookbook [oreilly.com]. The 'Cookbook'-format (specific real-world problems and possible solutions) makes for extremely useful books.

JP

News? Publish date = Nov 2002 (2, Insightful)

walterbyrd (182728) | more than 10 years ago | (#6151370)

This book has been out for nearly a year. Is this news?

Re:News? Publish date = Nov 2002 (0)

Anonymous Coward | more than 10 years ago | (#6151798)

This book has been out for nearly a year

Nice of you to round up by adding another 5 months - it's only frickin' June for heaven sake!

PHP=Poor Human's Perl (-1, Troll)

Anonymous Coward | more than 10 years ago | (#6151410)

At least, that's always what I thought it stood for...

Excellent book, I heartily recommend it to any... (3, Informative)

Naum (166466) | more than 10 years ago | (#6151488)

...PHP developer.

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.

I'd give anything (2, Insightful)

digidave (259925) | more than 10 years ago | (#6151641)

to see a book that deals with advanced application design in PHP. The problem with PHP is that most PHP developers are amateurs who don't know the first thing about app design. At best, apps are written with objects used randomly to accomplish some tasks and mostly include files for 2 dozen reused functions (or functions that aren't even reused, but still included in every page).

At worst, every database connection is hard-coded in a different place and there are no comments anywhere.

In either case, my God help anyone who wants to add functionality. These same people need a good book on relational database design, or be subjected to 4 years of universigy RDBMS design courses like I was. IMO, if you aren't willing to slit your wrists to get out of an RDBMS design class, you haven't taken enough of them.
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...