Get flash to fully experience Pearltrees
Following are list of 15 most useful PHP code snippets that a PHP developer will need at any point in his career. Few of the snippets are shared from my projects and few are taken from useful php websites from internet. You may also want to comment on any of the code or also you can share your code snippet through comment section if you think it may be useful for others. 1.
Posted April 24th, 2010 in PHP The PHP CLI (command line interface) allows basic syntax checking of a PHP file. I'll show the basic usage of this in this post and then a couple of ways to check all files in a directory, and all files recursively down the directory tree as posted by a couple of people on Twitter. Note that the syntax checking only checks for syntax errors - it does not report the usage of variables which have not yet been defined, functions or class which have not be declared etc. This was posted by @chrisvoo ( http://twitter.com/chrisvoo ) to syntax check all the PHP files (or at least all files with a .php extension) in the current directory from a BASH command line: I retweeted the above and was replied to by @gurubobnz on Twitter ( http://twitter.com/gurubobnz ) with how to syntax check all .php files recursively down the directory tree from current directory:
PHP PSD Reader A few weeks ago, I wrote an article about this PHP which allow you to display any Adobe PSD file on screen. Very usefull to create preview of PSDs designed for clients, for example. One of the most common (and boring) problem for front-end developers is definitely cross-browser compatibility.
Random password generator PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length and strength. Just include this function anywhere in your code and then use it.
I'll start out by explaining some of the things I don't like about PHP. If I get this all out of the way, you can get to the useful stuff. I'll use this opportunity to say something instructive about how to use the language, based on its strengths and weaknesses, though, so it's not wasted time entirely. 3. The combination of the previous two statements adds up to a situation wherein most PHP programming consists of writing a few often-used control statements, loops, and echo statements, using very basic I/O, and looking up functions to do what you want done. This means, of course, that it's fairly easy for unskilled programmers to do work -- and hard for skilled programmers to do good work.
There are three operators that are complicated enough to get their own section, of which the first is the ternary operator. It is called the ternary operator because it takes three operands - a condition, a result for true, and a result for false. If that sounds like an if statement to you, you are right on the money - the ternary operator is a shorthand (albeit very hard to read) way of doing if statements. Here's an example:
As this book aims to be a complete guide to PHP, it would not be right not to list the entire selection of operators in the language, so here goes: If you have not used modulus since school, here's a quick refresher. To calculate $a % $b , you first perform $a / $b and then return the remainder. For example, if $a were 10 and $b were 3, $b would go into $a 3 whole times (making nine) with a remainder of 1. Therefore, 10 % 3 is 1.