Hi Welcome to the trendy PHP tutorial! during this PHP tutorial helps you learn the way to develop dynamic internet sites and web applications victimisation PHP from scratch. This PHP tutorial can assist you to be told PHP scripting language simply.
This PHP tutorial series covers all the topics of PHP such as introduction, data types, operators, creating , using variables, generating outputs, structuring your code to make decisions in your programs or to loop over the same block of code multiple times, creating and manipulating strings and arrays, defining and calling functions, PHP MySQL, PHP with Ajax, PHP with jQuery and PHP with XML and so on.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages and can be embedded into HTML . It was initially known as Personal Home Page. PHP (recursive acronym for
PHP: Hypertext Preprocessor) is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP. It is also a general-purpose language that you can use to make lots of projects, including Graphical User Interfaces (GUIs).
PHP was created by Rasmus Lerdorf in 1994. It’s currently maintained by the PHP Development Team.
What is a PHP File?
- PHP files can contain text, HTML tags and scripts
- PHP files are returned to the browser as plain HTML
- PHP files have a file extension of “.php”, “.php3”, or “.phtml”
PHP 7.4.0 is the latest version of PHP, which was released on 25 November.
Some important points need to be noticed about PHP are as followed:
- PHP can generate pages and files dynamically.
- PHP is a recursive acronym for “PHP: Hypertext Preprocessor”.
- PHP is a server side scripting language that is embedded in HTML.
- PHP is an object-oriented language.
- PHP is an open-source scripting language.
- PHP is simple and easy to learn language.
- PHP Syntax is C-Like.
- It runs on various platforms (Windows, Linux, Unix, etc.).
- PHP can access cookies variable and set cookies.
- PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
Familiarity with syntax:
PHP has easily understandable syntax. Programmers are comfortable coding with it. We will now have a look at a simple PHP program.
<?php echo "Hi, I'm a PHP script!"; ?>
Characteristics of PHP
- Simplicity : Its popularly known for its simplicity, familiarity and easy to learn the language as the syntax is similar to that of ‘C’ or Pascal language. So the language is very logical and well organized general-purpose programming language. it comes with a lot of pre-defined functions, which makes the task of the programmer easy. Even people with a normal programming background can easily understand and capture the use of language. PHP is very advantageous for new users as its a very reliable, fluent, organized, clean, demandable and efficient.
- Fast Performance: Users generally prefer fast loading websites. PHP code runs faster than most of programming languages because it runs in its own memory space. Not only that, but its connection with databases is also fast and efficient.
- For any web development, speed becomes an important aspect which is taken care of by PHP.
- Objective oriented: PHP supports object-oriented programming features like data encapsulation, inheritance, abstraction, polymorphism, etc. The Object-oriented programming feature was added in PHP5. This feature helps in building complex reusable web pages and makes PHP comparable to powerful object-oriented languages like Java and Python.
- Efficiency: PHP is a versatile, reliable, and efficient programming language. The memory management of PHP is very efficient. Great session management, eliminating unnecessary memory allocation, are some of the features that make PHP efficient.
- Open Source: PHP is open-source, which means it can be downloaded and used freely. Even in companies, the total cost is reduced for software development providing more reliability and flexibility. It supports a popular range of databases like MySQL, SQLite, Oracle, Sybase, Informix, and PostgreSQL.
- Case-sensitive: PHP is a partially case-sensitive language. Although functions names are not case-sensitive, other things in PHP are case-sensitive.
- Variable names
- Constructs (if, if-else, if-elseif, while, do-while)
- Keywords (such as true and false)
- User-defined functions and class names
- Security: PHP has many pre-defined functions for data encryption. Security algorithms such as Sha1 ( secure Hash algorithm 1) and MD5(Message digest 5) are used to encrypt the strings in PHP. Filter_var and strip_tags functions help to keep the environment more secure and safe for users. It consists of multiple layers of security to prevent threads and malicious attacks.
- Cross-platform compatibility: PHP has cross-platform applications, running on Windows, Linux, Unix, Mac OS X, and an array of other supported operating systems. As PHP is platform-independent, it’s very easy to integrate with various databases and other technologies without re-implementation. It effectively saves a lot of energy, time and money.
- Error reporting and handling: PHP7 supports exception handling which is used to throw errors which can be caught at any time. PHP has predefined error reporting constants to generate an error notice or warning at runtime. E.g., E_ERROR, E_WARNING, E_STRICT, E_PARSE.
- Loosely Typed Language: PHP allows us to use a variable without declaring its datatype. It will be taken automatically at the time of execution based on the type of data it contains on its value.
- Memory and CPU usage information: PHP has functions like memory_get_usage() and memory_get_peak_usage(), which can help the developers optimize their code. In the similar way, the CPU power consumed by any script can be retrieved for further optimization.
- Magic Constants: PHP provides many built-in magic methods starting with __(double underscore) which are called during specific events.
(__DIR__), class name (__CLASS__), namespace (__NAMESPACE__), function name (__FUNCTION__), method name (__METHOD__), line number (__LINE__), file path (__FILE__).
Ways to Write PHP tag
When PHP parses a file, it looks for an opening and closing tags, which are
?> which tells PHP to start and stop interpreting the code written inside.
Three types of tags are available in PHP.
- Normal tag(<?php ?>)
- Short echo tag(<?= ?>)
- Short tag(<? ?>)
|1.0||8 June 1995|
|2.0||1 November 1997|
|3.0||6 June 1998|
|4.0||22 May 2000|
|5.0||13 July 2004|
|7||3 December 2015(stable)|
|7.3||6 December 2018|
|7.4||28 November 2019|
|8.0||26 November 2020|
|8.1||25 November 2021(Current Version)|
PHP 8.1 features
- Support for `readonly` properties was added.
- After the introduction of array unpacking in PHP 7.4 with consecutive numbered keys, PHP 8.1 introduced support for array unpacking with string keys.
- PHP 8.1 added support for using `new` in initializers.
- A new syntax was added for creating callables.
- PHP 8.1 brought support for Pure Intersection Types, after in the introduction of union types in PHP 8.0.
HTML : HTML is the standard markup language for Web pages. HTML is used to design static webpage.
CSS: CSS is the language we use to style an HTML document.