PHP is an open-source, server-side interpreted programming language primarily used for building dynamic web pages. The original abbreviation stood for "Personal Home Page Tools", but it is now used as an acronym for "PHP: Hypertext Preprocessor".
If client-side languages such as HTML, CSS, or JavaScript are only interpreted by the web browser when a web page is opened, the PHP code is already executed on the webserver. The PHP scripts then generate HTML output, which is sent to the web browser.
The main scope of PHP is server-side programming, especially dynamic websites and applications. It is also well suited for building office applications and command-line programming.
WordPress, TYPO3, Joomla, and Drupal, four of the most popular content management systems, are based on PHP. According to a market analysis by W3Techs, the programming language is currently used on 82.3% of all web pages (as of November 18, 2016).
This PHP tutorial is primarily intended for beginners and provides an overview of server-side programming. However, some examples require some basics in web development. In addition, it is important to familiarize yourself with the HTML markup language beforehand.
The fastest way to learn PHP is to understand the examples listed here and adapt them to the needs of your web project. All you need for server-side programming with PHP is a web server including a PHP interpreter, a text editor (eg Notepad +++ or Vim and your web browser.
Install PHP
To manage the PHP scripts, it is necessary to have a Web server able to interpret the programming language, and supplemented by a PHP interpreter. It is a software component capable of deciphering passages from a file containing PHP code.
Typically, the PHP interpreter is integrated as a server module or FastCGI. It is not recommended to use the interpreter as a CGI program because performance is not optimal. In practice, PHP is often used for configuration in combination with the Apache HTTP server.
Web Stacks: Software stacks are offered as pre-configured software packs. To learn PHP, it is recommended to use the complete XAMPP package, which includes a local installation of the Apache webserver including the MariaDB database system, as well as the programming languages Perl and PHP.
the URL"HTTP: //localhost/test.php" is like asking your web browser to deliver the test.php file to the webserver. The Apache HTTP Server, or the webserver software of your choice, retrieves the file from the appropriate directory. The .php extension indicates that the file contains PHP code.
The phpinfo () function is short for the default phpinfo (INFO_ALL), which displays detailed information about your web server's PHP configuration. If no version of PHP can be found, the web browser displays an error message or passes the PHP code to the browser without interpreting it.
If PHP was installed correctly, you can write the first custom script using the echo function. Unlike phpinfo (), echo is not a function in the proper sense. Rather, it is a language construct that generates a subsequent string of characters as text.
Thanks to the <h1> tag, the Hello World! is interpreted by the web browser as a first-level title. It is followed by an automatic line break and the text paragraph <p>.
PHP offers a lot of freedom about the name of the variables, which you can name as you wish as long as the following constraints are respected:
Each variable must begin with the dollar sign.
- A variable name is a string made up of letters, numbers, and dashes, like $ example_1.
- A valid variable name always starts with a letter or a hyphen, like this: $ example1 or $ _example, but never with a number (false: $ 1example).
- PHP is case sensitive: the scripting language distinguishes between upper and lower case. $ example is, therefore, different from $ Example.
- The name of the variable must not contain spaces or line breaks (false: $ example 1 )
- Strings that PHP reserves for other purposes cannot be customized (eg $ this )
This is particularly effective if a variable occurs more than once in a script. In this case, a single modification is enough to correct all the occurrences, since it is here that the value of the variable is defined.
This is where the power of the PHP course content can be integrated as variables. This functionality forms the basis of dynamic web development. Unlike static pages, which are available as ready-to-use HTML pages, dynamic web pages are only created when the user seeks to view them.
The advantages of this design concept are obvious: when elements of the website (for example in the footer area) are changed, there is no need to make manual adjustments on every subpage of the web project.
If a variable is defined more than once in a script, each new definition replaces the previous one. Echo always implements the current value of a variable.
The echo can, as needed, be used with single (') and double (") quotes. When you only want to edit text, the choice of quotes is not important. variables come into play.
The variables
The echo language construct offers more than a single line of text which, ultimately, could be implemented without PHP, based on HTML. The real added value of echo is based on variables, elements that allow the instruction to create dynamic texts.