PHP is probably the most widely used programming language around. Before I begin teaching the basics, I would like to explain a little about the history first. There is just something about knowing how it all started that makes it easier to code in the end. Here is some information that I found relevant that I found on Wikipedia:
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers. Originally created by Rasmus Lerdorf in 1994, the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group. While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor.
PHP development began in 1994 when Rasmus Lerdorf wrote a series of Common Gateway Interface (CGI) binaries in C, which he used to maintain his personal homepage. He extended them to add the ability to work with web forms and to communicate with databases, and called this implementation “Personal Home Page/Forms Interpreter” or PHP/FI.
PHP/FI could be used to build simple, dynamic web applications. To accelerate bug reporting and improve the code, Lerdorf initially announced the release of PHP/FI as “Personal Home Page Tools (PHP Tools) version 1.0” on the Usenet discussion group comp.infosystems.www.authoring.cgi on June 8, 1995. This release already had the basic functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax resembled that of Perl, but was simpler, more limited and less consistent.
Early PHP was not intended to be a new programming language, and grew organically, with Lerdorf noting in retrospect: “I don’t know how to stop it, there was never any intent to write a programming language […] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way.” A development team began to form and, after months of work and beta testing, officially released PHP/FI 2 in November 1997.
The fact that PHP was not originally designed, but instead was developed organically has led to inconsistent naming of functions and inconsistent ordering of their parameters. In some cases, the function names were chosen to match the lower-level libraries which PHP was “wrapping”, while in some very early versions of PHP the length of the function names was used internally as a hash function, so names were chosen to improve the distribution of hash values.
Zeev Suraski and Andi Gutmans rewrote the parser in 1997 and formed the base of PHP 3, changing the language’s name to the recursive acronym PHP: Hypertext Preprocessor. Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP’s core, producing the Zend Engine in 1999. They also founded Zend Technologies in Ramat Gan, Israel.
On May 22, 2000, PHP 4, powered by the Zend Engine 1.0, was released. As of August 2008 this branch reached version 4.4.9. PHP 4 is no longer under development nor will any security updates be released.
On July 14, 2004, PHP 5 was released, powered by the new Zend Engine II. PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects (PDO) extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements. In 2008 PHP 5 became the only stable version under development. Late static binding had been missing from PHP and was added in version 5.3.
The following “Hello, World!” program is written in PHP code embedded in an HTML document:
<!DOCTYPE html> <html> <head> <title>PHP "Hello, World!" program</title> </head> <body> <?php echo '<p>Hello, World!</p>'; ?> </body> </html>
However, as no requirement exists for PHP code to be embedded in HTML, the simplest version of Hello, World! may be written like this, with the closing tag omitted as preferred in files containing pure PHP code
<?= 'Hello, World!';
As well, there is no requirement that a PHP file contain PHP code at all – the interpreter will output data outside of PHP tags unchanged so a simple text file containing “
Hello, World!” will give the same output.
The PHP interpreter only executes PHP code within its delimiters. Anything outside its delimiters is not processed by PHP, although non-PHP text is still subject to control structures described in PHP code. The most common delimiters are
to close PHP sections. The shortened form
, in XHTML and other XML documents, creates correctly formed XML processing instructions. This means that the resulting mixture of PHP code and other markup in the server-side file is itself well-formed XML.
Variables are prefixed with a dollar symbol, and a type does not need to be specified in advance. PHP 5 introduced type hinting that allows functions to force their parameters to be objects of a specific class, arrays, interfaces or callback functions. However, before PHP 7.0, type hints could not be used with scalar types such as integer or string.
Unlike function and class names, variable names are case sensitive. Both double-quoted (“”) and heredoc strings provide the ability to interpolate a variable’s value into the string. PHP treats newlines as whitespace in the manner of a free-form language, and statements are terminated by a semicolon. PHP has three types of comment syntax:
/* */ marks block and inline comments;
# are used for one-line comments. The
echo statement is one of several facilities PHP provides to output text.
In terms of keywords and language syntax, PHP is similar to the C style syntax.
while loops, and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.
That is just a brief overview of what can be found on Wikipedia that covers this topic. Wikipedia has so much information, but I felt that this was enough for you to understand the history of how it all got started. There was even some information on the syntax which is extremely important to know. If you have any questions or would simply like to ask a question, I am more than happy to answer in the comments below. If you would like for me to go into more detail about the syntax, I would be happy to do so in a future article. For now, I will leave you with this.
Leave A Comment