Useful Handy PHP code Snippets


What is PHP Snippet

Snippet is a reusable PHP code which can be incorporated into larger programming php functions and are easy and simple way to run PHP code snippets on websites.

What is PHP

PHP (Hypertext Preprocessor) is an open-source, interpreted, and object-oriented scripting language that is primarily executed on Linux Web servers. PHP, originally derived from Personal Home Page Tools, now stands for PHP: Hypertext Preprocessor, which the PHP FAQ describes as a "recursive acronym."

PHP executes on the server, while a comparable alternative, JavaScript, executes on the client. PHP is an alternative to Microsoft's Active Server Page (ASP) technology. As with ASP, the PHP script is embedded within a Web page along with its HTML. Before the page is sent to a user that has requested it, the Web server calls PHP to interpret and perform the operations called for in the PHP script. An HTML page that includes a PHP script is typically given a file name suffix of ".php" ".php7," or ".phtml". Like ASP, PHP can be thought of as "dynamic HTML pages," since content will vary based on the results of interpreting the script.


Welcome to Handy PHP

Handy PHP is more than just a resource for PHP related information. Here at Handy PHP, we pride ourselves on our friendly, active and experienced community. From beginners to professionals, everyone will find something to talk about at Handy PHP.

Create Your Own PHP Function

As you write more and more scripts in any language, you will find that you have to use the same bits of code over and over. For example, in PHP you may use the echo function several times in each script. Now when the creators of PHP developed the scripting language, they realized that the job that echo performs was important and they created the function so that you wouldn't need to explain to the server how to echo every time you want to output data. Without the echo function, you would need to write a large block of code to do the same thing. In PHP like most languages, you have the ability to define your own functions for a script. Lets say that we wanted to print out a list of numbers from 1 to 10. Here is the code we would use without a function

CODE: PHP Snippet
for($x=1;$x<=10;$x++){
echo "$x
\n";
}
?>

That would output the following:
Output:
1
2
3
4
5
6
7
8
9
10

10 PHP Myths Dispelled

The 10 myths which he decided to tackle are as follows:

  1. PHP is not a truly Object-Oriented Language
  2. PHP is only good for web applications
  3. PHP isn't really for serious developers
  4. PHP apps all look the same
  5. PHP Code is rife with in-line SQL statements
  6. PHP Encourages Sloppy Code
  7. PHP is slow because it's interpreted
  8. PHP doesn't have a good IDE or Debugger
  9. PHP doesn't follow MVC
  10. PHP code is a mess of include and require statements that break easily
Search
Handy PHP code Snippets
handyphp.com Contributors
You can put anything you want post here. Please email to support@handyphp.com
Snippet of the Month
Get Real IP Address of Client

function getRealIpAddr()
{
if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif(!emptyempty ($_SERVER['HTTP_X_FORWARDED_FOR']))
//to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip; }