what is php? Hello World First Program

what is php?php first program

What is PHP:

PHP is a server side scripting language. that is utilized to create Static websites or Dynamic websites or Web applications. PHP stands Hypertext Pre-processor, that prior represented Personal Home Pages.

PHP scripts must be interpreted on a server that has PHP installed. The client PCs getting to the PHP scripts require a web program as it were.

What is Scripting Language?

Before presenting the PHP language, it is useful to briefly identify its place on the Internet. How, indeed, to understand the usefulness of a scripting language if the notion of “server” is still fuzzy?

The Internet is a network of networks, made up of computers that are interconnected. Its structure is with a grid, not pyramidal. There are many rungs, but the higher rungs are, in fact, quite close to the base, and are, above all, in very large numbers. These steps are interchangeable. When your top echelon is absent, broken down, or gone, you can use another rung of the same type. In short, two machines are usually interchangeable.

This makes it very difficult to “run” the Internet. Like any good communication process, The Internet has a language (in fact several languages) which depends on the service you want to use (web, mail, ftp, etc.). Whatever the service in question, this language is common to all computer machines, and is indifferent to platforms. The data from the Internet are therefore, sometimes with some reprocessing, reusable by any computer. Thus, a website is built independently of the platform on which it is designed. It’s the software that adapts to machines. There is a web browser (Netscape) for PC and another version for Mac. The data they use, on the other hand, are independent of the operating systems (Windows, MacOs, Linux, etc.). The the most well-known components of the Internet are the Web (World Wide Web) or mail electronic (e-mail).

Let’s focus on the web, because that’s what PHP is all about. Let us admit that you want to visit the Google search engine website. You give the address to your browser, you launch the search, and, a few seconds later, the home page of the site is displayed on your screen. In fact, behind this action hides a whole client-server interaction, essential to integrate to fully understand how PHP works. Your browser, the client, queries a server, asking it for the home page of a site. The server is a machine that hosts the website in question. This machine must be, in principle, permanently connected to the network. Concretely, these are the hard disks of this machine that store the HTML or PHP pages that will be requested by Internet users. For that the server is able to answer you, certain programs and services must be are present and functional within it. In the case of a website, the server must has a web server, i.e. a program for interpretation and dissemination pages requested by Internet users. Your browser requests the page, the web server receives and understands your request, it searches for the page in question and, if available, you return it. In fact, it only returns the source code of the page, usually HTML, but it can be an image or an animation. The formatting, construction and display of the page fall to your browser.

PHP is an HTML scripting language, that is, it works in relation to the language HTML (HyperText Markup Language). It works on the server side, not the server side. client, and allows you to generate web pages “on the fly” or dynamically. Concretely, a PHP script is integrated to the source code of an HTML page. When the page is called, the PHP script is interpreted, and everything is delivered to the web server which, in the end, responds to the internet user’s browser. Surfer gets a very classic HTML page, except that this page

did not exist as such on the web server. We then say that the page was created “at the fly “, or dynamically. More concretely, let’s take a very simple HTML page of which here is the source code:

To integrate this script into the HTML page, simply insert the code between the <body> tags here and </body> of the page. Which then gives us this:

It’s that simple. As you can see, the PHP script is surrounded by a start tag and an end tag (ie <? php and?>). This is information which, on reading of the page, tell the server to interpret this information as PHP, and not more like HTML. A script is defined by Linux France jargon as follows: “A series of simple instructions, loosely structured, allowing some tasks to be automated […] “. Put it that way, it’s pretty scathing. Clearly, a PHP script not only allows you to generate text or HTML code, but also to send an email, to access a database, to launch a program on the server, etc. It is therefore possible to count the number of visitors on your page, manage a guestbook or even create full-fledged web applications, such as content managers (PHPNuke, DaCode, SPIP, etc.) or work tools collaborative (PHPGroupware, for example). In fact, PHP has the same functionality as other scripting languages. Its big its strength lies in its resolutely web-oriented operation. In native, it is more than twenty databases which are supported by PHP, without the user having to do anything it would be. All the major internet protocols work, too, without any other form of process with PHP: SMTP, POP3, IMAP, FTP, SNMP, etc.

History of PHP:

The first version of PHP was not. These were just a few tools developed by Rasmus Lerdorf for the needs of his personal website. In the course of 1993, Mr. Lerdorf had started to develop scripts in C and Perl. From there could to set up, in September 1993, the first bookshop. Tired of having to rewrite again and always the same pieces of code, Mr. Lerdorf had the idea of ​​separating his logic from the programming of HTML, in order to be able to reuse certain portions more easily code. For the first version of PHP as a scripting language to emerge, there was no shortage to the library only an interpreter capable of analyzing the HTML code, to locate tags and call the related functions. This was done in November 1993, date which Mr. Lerdorf locates the birth of the very first version of PHP. The first one grind of the language did not have very great ambitions. PHP is then limited to one interpreter that analyzes an HTML page, outputs tags (inspired by SGML), and calls the functions corresponding to these tags. All this for what purpose? In order to count and record the number of visitors viewing a curriculum vitae on his personal site. Rasmus Lerdorf summed up his motivations to fatigue with Perl, deemed too slow and equipped with an overly restrictive analyzer. This first version had very limited success, and for good reason … it was never published. It was not until February 1994 that a first version of PHP was finally released.

PHP against its competitors (ASP, JSP, etc.):

PHP Vs Perl :

Perl is primarily a system scripting language, born to replace sed and awk. In front of him: PHP, a web-born scripting language for the web. Points of comparison, if they exist, shouldn’t forget that Perl isn’t primarily about building websites. Basically, PHP includes many more libraries than Perl. For Perl, you often have to go search for a desired library on CPAN. In contrast, Perl, in the end, has a lot more libraries than PHP. There, PHP pays the price of its young age in the face of an age language already venerable. Not to mention libraries, Perl solutions are already very numerous. However, the particular dynamism of the PHP community is on the way to filling this gap. A web oriented language, PHP is easier to maintain and upgrade than Perl. Touch up or quickly adapting an entire site geared towards Perl remains more difficult than if the site has of architecture in PHP. Perl has also adapted to the Web. As he created a new process on the server each time new request, Perl has since been able to standardize its relationship with the web server. The problem has indeed been fixed by the appearance of mod_perl or FastCGI.


ASP (Active Server Pages) is a scripting language developed by Microsoft. PHP and ASP are quite similar in their philosophy and in their implementation. In both cases, the code of the script is inserted directly into the web page. Until PHP 3, ASP had a very clear advantage over PHP: PHP did not manage sessions. With the introduction of this management mode native in PHP 4, the advantage is lost. If PHP 3 must imperatively be used, for license reasons for example, there are anyway alternatives, like PHPLib, which allow you to manage the sessions anyway. The big drawback of ASP compared to PHP is its very strong dependence on Windows platform. ASP can only be deployed in a Microsoft environment. He There is certainly a port under UNIX, thanks to the solution set up by Sun with Chilisoft ASP, but this falls short of what PHP can offer. PHP was not developed for platform in particular, which opens up much wider horizons in terms of portability applications as well as scalability. PHP works under Linux as well as under Windows NT, without having to resort to third-party programs. A script in PHP can be reused much more easily as a script in ASP. PHP has often been criticized for having rather long response times. This point can be enhanced with caching software solutions. Zend Accelerator or PHP Accelerator thus significantly reduce PHP response times. Another big difference between PHP and ASP: PHP interfaces natively with all industry standard database management systems, whereas ASP must go through ODBC. This difference can be viewed in two ways. On the one hand, better control database and maybe even better performance work in PHP’s favor. On the other hand, functions vary from database to database, which requires adapting code for each database, while in theory ASP will only require a few modifications. In fact, even if nothing is offered as standard, there are solutions (presented in this book) of abstraction layers for PHP, but, above all, the implementation SQL language varies greatly from one database server to another, the adaptation of the code depending on the database server is unavoidable (it is for this reason that Rasmus Lerdorf is not in favor of integrating an abstraction layer into PHP). Today, ASP is moving heavily to .Net, the “n-tier” web services platform of Microsoft. In this it is similar to Java with J2EE from Sun. For its part, PHP will become more and more a “serious” language, including variable declaration, typing, etc. Faced with ASP, PHP can also play the price card. Take the case of a company that wants to develop a Microsoft solution.


Again, comparing PHP to JSP is a tricky exercise. The Principe of fonctionment is a little different: PHP was designed to integrate with HTML code, while JSP is a use of Java allowing to manage scripts integrated into the HTML code. In fact, a JSP page is systematically converted into a servlet. While running a PHP script is composed of document analysis, compilation (in opcode) and execution itself, that of a JSP script is composed of the analysis of the document, of the of the servlet (which mainly consists of converting the HTML code into Java calls “displaying” this same code), compiling the servlet, and finally the actual execution. It is possible to imagine that it is the “heaviness” of this work that makes the servlets systematically cached (which sometimes creates surprises for developers beginners), while the use of caches is only optional with PHP (it is therefore important to take this difference into account when comparing performance). While with PHP, everything goes through the use of PHP scripts, with JSP, the use of scripts (scriptlets) should be kept to a minimum. These scriptlets should as much as possible be content to call Beans methods. This has the disadvantage of having to systematically working at the same time in two different spaces: on one side the web pages, on the other the Beans. Each modification will result in a new compilation of the Beans and, possibly, the generation of a new archive to deploy in the server space. With PHP, a simple modifying the script in the server space is sufficient. On the other hand, the compilation of Beans will make sure you don’t encounter stupid syntax errors when executing the code (problem that will be encountered with PHP). But that’s not what will ensure you have a code that works (although it is true that it contributes greatly). In fact, JSP is designed as one element among many in a J2EE architecture. For large-scale sites, the advantage is indisputable: it is easier to share the tasks and skills of a team on developing code in Java. Of even, the “n-tier” architecture of Java (allowing the call of objects made available on a remote server) offers a wider range of solutions (and with more robust solutions) for sites with a high audience and dense traffic. But to achieve this result, many are the design standards or rules to be respected which does not facilitate the learning of language. Note, however, that many of these rules can very well be applied to PHP (such as the MVC model). In this case, it is just the responsibility of the developer team to impose those design choices on ourselves or us.

Via J2EE, Java makes the explosion of an application platform much easier and simpler than in the case of PHP. For PHP, the script must theoretically be executed on the machine which receives the request (script processing on the machine hosting the web server). Also it is more difficult to set up a split structure, more modular, and holding heavy charges. Interfacing with databases is carried out using JDBC drivers, which makes it possible to communicate with any type of database server using a common language, but, as we said before, this is not the case by default for PHP (although some solutions exist). However, as has also been said, SQL language varies substantially from one database server to another, making it necessary to use dedicated code (which greatly reduces the value of such an interface). For a specific application, the choice of Java may be wise. For example, we do not can not speak of a real connection pool in PHP, while for Java it is present in the container of EJB-J2EE. In the same spirit, it is possible to share Beans by common with all executed scripts (which PHP does not offer). Note that Java was designed to be object oriented (like Smalltalk or ObjectiveC). PHP was not created for object programming, but it is still possible to program in this way, even if all the properties to which we could expect us are not available. Today things are changing, and the Zend Engine 2 goes further in the sense of object programming. Fortunately, as with PHP, there are more or less complete open-source solutions.

Comparative table of scripting languages:

For scripting languages, it is possible to discern some major factors to consider when choosing one of them: ease of learning (accessibility), power with regard to the complexity, portability and available environment (online resources, tools, etc.). For ASP, PHP, Java, Perl and PHP, the situation can be summarized as follows:

Accessibility + ++ +++
power ++ ++ +++ ++
Portability ++ +++ +++
Environment ++ ++ +++ +++

Based on the criteria we have defined, PHP seems to have the most advantages. He It doesn’t matter whether, in absolute terms, PHP is more powerful than Java, for example. But in on the other hand, it is a question of whether, in the case of using a scripting language to render a dynamic website, the investment in time required to master Java is justifiable at look at the ease of use of PHP. French jargon defines the objectives of a language of script as follows: “Make it simple, quick, utility”. With this in mind, PHP is clearly the more adapted.

Why PHP?

Many applications have already been written in PHP and websites (“personal” like professionals) who switch to PHP can no longer be counted. Why does a webmaster make the choice of PHP? Between development ambition and political preference, PHP’s strengths are varied. In addition, the performance aligned by PHP in its multiple consumer applications can also be attractive. We have collected the testimonials of two developers who have chosen PHP.

Syntax of PHP:

The parts corresponding to the PHP code are declared by means of tags. There are many types of tags according to your preferences, habits, and the configuration of PHP on the server or will run your scripts. There are four different types of tags in php:

<? php…?>:

This type of tag is the most common. It is accepted by default by the interpreter.

<script language = “php”>…</script>:

This type of tag is also accepted by default by the interpreter.

<? …?>:

These short tags are called “short tags”. They are not accepted by default, this is part of the PHP configuration.


These tags are there to get the same tags as for ASP. They are not accepted by default, this is part of the PHP configuration.

Mostly used syntax of php is




PHP Hello world:

“Hello World.” is the first program most starting programmers will learn to write in some random language. Here is a case of how to print “Hello World!” in PHP.

The following output will display in the web browser

Related Article:


settype and gettype function

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button