PHP Tutorials for beginners


PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is a cross-platform, HTML-embedded server-side scripting language and is especially suited for web development.

PHP logo


  • Server-side means that PHP scripts execute on the Web server, not within the browser on your local machine.
  • Cross-platform means that PHP scripts can run on many different operating systems and Web servers. PHP is available for the two most popular Web server configurations IIS and Apache.
  • HTML embedded scripting language means that PHP statements and commands are actually embedded in your HTML documents. When the Web server sees the PHP statements in the Web page, the server executes the statements and sends the resulting output along with the rest of the HTML. PHP commands are parsed by the server much like Active Server Pages or Cold Fusion tags.

The basic syntax of PHP is similar to C, Java, and Perl, and is easy to learn. PHP is used for creating interactive and dynamic web pages quickly, but you can do much more with PHP.

A simple example

<title>First PHP example</title>
echo "This is a simple PHP script!"; 

In the above example we have written a HTML script with some embedded code to display some text. The PHP code is enclosed in special start (<?php) and end (?>) tags that allows to go in and out of PHP mode. The extension of a php file is ".php".

Benefits of PHP

  • PHP is an open source software.
  • PHP costs nothing, it is free to download and use.
  • PHP is a server-side scripting language and is used for websites and the web applications.
  • PHP scripts are executed on the server.
  • PHP supports a wide range of databases.
  • PHP runs on various platforms like Linux, Windows, Unix etc.
  • PHP supports most web servers (for example Apache, IIS).
  • PHP converses with several network protocols.

Features of the w3resource PHP tutorials

In this series of tutorials, we have covered PHP 5 in detail. While creating this, we have to take care that learners can master the basics of PHP and can be prepared to develop web based applications.

Here is a list of features we have included in all of the chapters :

1. We have started with a clear and simple description.

2. We have given a Syntax / Usage so that you can remember how to write it.

3. Example(s) to show how the associated concept is implemented.

4. We have shown the Output of the usage.

5. View the example in a browser.

6. Pictorial presentation to help you to understand the concept better.

Next: Installing php and php extensions on windows

PHP: Tips of the Day

PHP - How do I implement a callback in PHP?

The manual uses the terms "callback" and "callable" interchangeably, however, "callback" traditionally refers to a string or array value that acts like a function pointer, referencing a function or class method for future invocation. This has allowed some elements of functional programming since PHP 4. The flavors are:

$cb1 = 'someGlobalFunction';
$cb2 = ['ClassName', 'someStaticMethod'];
$cb3 = [$object, 'somePublicMethod'];

// this syntax is callable since PHP 5.2.3 but a string containing it
// cannot be called directly
$cb2 = 'ClassName::someStaticMethod';
$cb2(); // fatal error

// legacy syntax for PHP 4
$cb3 = array(&$object, 'somePublicMethod');

This is a safe way to use callable values in general:

if (is_callable($cb2)) {
    // Autoloading will be invoked to load the class "ClassName" if it's not
    // yet defined, and PHP will check that the class has a method
    // "someStaticMethod". Note that is_callable() will NOT verify that the
    // method can safely be executed in static context.

    $returnValue = call_user_func($cb2, $arg1, $arg2);

Modern PHP versions allow the first three formats above to be invoked directly as $cb(). call_user_func and call_user_func_array support all the above.


  1. If the function/class is namespaced, the string must contain the fully-qualified name. E.g. ['Vendor\Package\Foo', 'method']
  2. call_user_func does not support passing non-objects by reference, so you can either use call_user_func_array or, in later PHP versions, save the callback to a var and use the direct syntax: $cb();
  3. Objects with an __invoke() method (including anonymous functions) fall under the category "callable" and can be used the same way, but I personally don't associate these with the legacy "callback" term.
  4. The legacy create_function() creates a global function and returns its name. It's a wrapper for eval() and anonymous functions should be used instead.

Ref : https://bit.ly/2Zmqil0