What’s PHP (Hypertext Preprocessor)?
PHP (Hypertext Processor) is a general-purpose scripting language and interpreter that’s freely accessible and broadly used for net growth. The language is used primarily for server-side scripting, though it will also be used for command-line scripting and, to a restricted diploma, desktop purposes. The acronym PHP was initially derived from Private Residence Web page Instruments, nevertheless it now stands for PHP: Hypertext Preprocessor, which the PHP Group’s documentation describes as a “recursive acronym.”
When used for server-side scripting, PHP is added to a webpage for the aim of producing dynamic content material when the web page is accessed by a consumer browser. The online server runs the script earlier than transmitting the web page to the browser. To help this course of, the net server requires PHP to be put in on the server, together with a PHP parser — both a Frequent Gateway Interface (CGI) parser or a server module.
When a consumer requests a webpage from the server, the parser interprets the PHP portion of the web page, performs the operations known as for within the PHP script, and generates the Hypertext Markup Language (HTML) that outcomes from these operations. The HTML is then despatched to the consumer browser, together with every other HTML on the web page, offering a seamless rendering of the content material. Webpages that comprise PHP script are thought-about to be dynamic HTML pages as a result of content material varies primarily based on the outcomes of decoding the script.
Working with PHP for server-side scripting
A webpage is likely to be made up fully of a PHP script, or it would comprise a number of PHP scripts which might be embedded inside commonplace HTML parts. In both case, the webpage itself usually is assigned the .php file extension, which informs the net server that the web page incorporates PHP script. The next code offers an instance of a easy HTML web page named check.php that incorporates an embedded PHP script that presents the day’s date:
<h3>Instance of HTML in motion</h3>
$textual content = "This can be a check HTML script.";
$date = date("M j, Y") ;
echo $textual content." At the moment's date is <b>".$date."</b>."
A lot of the web page’s content material is fundamental HTML that features commonplace <head> and <physique> parts. Nevertheless, the <physique> part additionally incorporates a PHP script, which is enclosed within the PHP begin and finish tags — <?php and ?>, respectively. PHP scripts should at all times be enclosed in these tags, whether or not they take up your entire web page or are embedded because the one proven right here.
The script on this instance defines the $textual content variable, which is assigned a string worth, and the $date variable, which is assigned the present date retrieved by the date perform. The 2 variable definitions are adopted by an echo assertion that concatenates the variables, together with extra textual content. PHP makes use of a interval (.) to concatenate a number of parts. The echo assertion additionally incorporates commonplace HTML markup — <b> and </b> — which specifies that the date ought to be displayed in daring textual content.
When a consumer browser accesses the check.php web page, the net server and PHP parser learn the PHP script and return common HTML. This determine reveals the webpage as it’s displayed within the Google Chrome browser. The textual content beneath the primary heading has been generated by the PHP script.
Most main working techniques help PHP, together with Linux, macOS, Home windows and plenty of Unix variants, as do most of in the present day’s net servers, similar to Apache and Microsoft Web Data Companies. PHP also can interface with a variety of database platforms, together with MySQL, SQLite3, MongoDB, dBase, PostgreSQL and IBM Db2. As well as, PHP can talk with different providers by its help for protocols similar to Light-weight Listing Entry Protocol, Web Message Entry Protocol and Easy Community Administration Protocol.
PHP is usually contrasted with Microsoft’s ASP.NET, an open supply net framework. As with ASP.NET, a PHP script might be embedded inside a webpage together with HTML parts.
PHP is free and open supply. Builders can discover the supply code on GitHub. PHP is presently licensed underneath the PHP License, model 3.01, which offers for its use in each supply and binary varieties, with or with out modifications. The license additionally outlines particular circumstances that have to be met to be able to use PHP. These principally must do with copyright notices, using the PHP identify and common acknowledgements. The most recent launch of PHP is 8.2.3, which turned accessible in February 2023.
See eight PHP options that show it is for extra than simply the net.