logo
logo
Sign in

What is PHP? Tutorial for beginners

avatar
Fashion make fashion

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. 

 
This does not get the actual code (the PHP script) but only the result of executing the script.

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. 
 
Although suitable for beginners, PHP offers an impressive array of features. 
The programming language is characterized by extensive database support; it can be used on multiple platforms, and it is available under a specific PHP license, which allows you to use and modify the source code. All of these elements make it a compelling tool.

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 makes PHP the most popular server-side programming language for web development. Hypertext Preprocessor alone is sufficient reason to familiarize yourself with the possibilities of PHP.

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. 
 
For the server, it is recommended to '' use the XAMPP local test environment, which is provided free of charge by Apache Friends for Windows, Linux, and macOS operating systems.

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. 
 
In principle, PHP is compatible with the main web servers. The interpreter is included in the PHP download pack. The current version is available for free download from the official php.net project website.

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. 
 
If this connection is completed by one of the database systems MySQL or MariaDB (for Linux), we speak of the operating system LAMP, WAMP (Windows), or, for macOS, MAMP.

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 PHP interpreter integrated into the webserver is now activated. Does it parse the document from the opening PHP tag <? Php, which signals the start of PHP code. The interpreter can execute PHP code and generate HTML output, provided by the webserver to the browser.

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 PHP interpreter uses the variables to load the individual elements of the Web page to be accessed: to do this, it uses different databases, the elements of which it assembles in an HTML page adapted to a specific request.

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. 
 
On the contrary, it suffices to update the entry in question in the database. This way, the revision is automatically adopted for all web pages that include the corresponding data as variables.

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.
collect
0
avatar
Fashion make fashion
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more