PHP 01
PHP 01
https://www.w3schools.com/php/php_supe
rglobals.asp
Chapter 1
Introduction to PHP
What is PHP?
● PHP is faster than other scripting languages, for example, ASP and JSP.
○ PHP is faster than other scripting languages, for example, ASP and JSP.
○ PHP is a server-side scripting language, which is used to manage the
dynamic content of the website.
Features of PHP
● Open-Source and Free: PHP is firstly open source which means
anyone can use PHP code without any licensing (free of cost). Along
with this one can run PHP on any operating system like Windows,
macOS, Linux, Unix and more.
● PHP Server-Side Scripting: PHP code executes on the server before
sending HTML content to the user’s browser, allowing for the dynamic
generation of web pages and handling user interactions.
● Interpreted language: PHP code is interpreted line by line,
eliminating the need for compilation and simplifying development and
testing processes.
● Database connectivity: PHP integrates seamlessly with various
databases like MySQL, PostgreSQL, ODBC , and Oracle, facilitating
data storage and retrieval for web applications.
● Object-oriented programming (OOP): PHP supports OOP concepts
like classes, objects, inheritance, and polymorphism, enabling better
code organization and modularity.
● Built-in functions: PHP comes with a rich set of built-in functions for
various tasks such as string manipulation, date and time handling, file
handling, and more, reducing the need for external libraries.
● Session management: PHP allows for user session management,
enabling personalized experiences and storing user data across
multiple page visits.
● Security features: While security considerations are essential for any
development language, PHP offers several built-in security features
and best practices to help mitigate vulnerabilities.PHP is a secure
language to develop the website. It consists of multiple layers of
security to prevent threads and malicious attacks.
● Web servers Support: PHP is compatible with almost all local servers
used today like Apache, Netscape, Microsoft IIS, etc.
● Performance: PHP script is executed much faster than those scripts
which are written in other languages such as JSP and ASP. PHP uses its
own memory, so the server workload and loading time is automatically
reduced, which results in faster processing speed and better
performance.
● Familiarity with syntax: PHP has easily understandable syntax.
Programmers are comfortable coding with it.
● Embedded: PHP code can be easily embedded within HTML tags and
script.
● Platform Independent: PHP is available for WINDOWS, MAC, LINUX
& UNIX operating system. A PHP application developed in one OS can
be easily executed in other OS also.
● Error Reporting - 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/Dynamically 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
● Web servers Support: PHP is compatible with almost all local servers
used today like Apache, Netscape, Microsoft IIS, etc.
● Control:Different programming languages require long script or code,
whereas PHP can do the same work in a few lines of code. It has
maximum control over the websites like you can make changes easily
whenever you want.
● A Helpful PHP Community: It has a large community of developers
who regularly updates documentation, tutorials, online help, and FAQs.
Learning PHP from the communities is one of the significant benefits.
5. security
6. error reporting
7. server support
8. database support
9. built in functions
10. familiar syntax
11. Embedded
12. php community
13. performance
14. Control
● PHP files can contain text, HTML, CSS, JavaScript, and PHP code
● PHP code is executed on the server, and the result is returned to the
browser as plain HTML
● PHP files have extension ".php"
Why PHP?
● PHP 7 is much faster than the previous popular stable release (PHP
5.6)
● PHP 7 has improved Error Handling
● PHP 7 supports stricter Type Declarations for function arguments
● PHP 7 supports new operators (like the spaceship operator: ⇔
Syntax
<?php
?>
Example:
<html>
<head>
</head>
<body>
</body>
</html>
Output:
Refer:
https://www.google.com/amp/s/www.geeksforgeeks.org/php-introduction/amp/
PHP EVOLUTION
PHP 2:
PHP 3 (1998)
Released in May 2000 , It Introduced several new features, including support for
XML, improved database connectivity, and the ability to create web services.PHP 4
came out with the Zend Engine 1.0, offering better performance and new features
like session management.
PHP 5:
PHP 5, released in July 2004, introduced the Zend Engine II, offering enhanced
performance and improved object-oriented programming (OOP) capabilities. It had
Enhanced error handling mechanisms, Improved performance, and memory
management.It introduced Better XML support with SimpleXML and DOM.It
introduced PHP Data Objects (PDO) for database access.
PHP 6 was intended to bring native Unicode support, but the project faced
numerous challenges and was ultimately abandoned. Many of its features were
backported to PHP 5.3.
PHP 7:
PHP 8:
● Enums.
● Fibers for better asynchronous programming.
● Readonly properties.
The evolution of PHP versions demonstrates the continuous effort to enhance the
language’s performance, flexibility, and functionality. Each release has introduced
features and improvements to make PHP more robust, secure, and
developer-friendly.
PHP INSTALLATION
https://www.w3schools.com/php/php_install.asp
DataTypes
https://www.geeksforgeeks.org/php-data-types/
Comments
https://www.w3schools.com/php/php_comments.a
sp
https://www.w3schools.com/php/php_comments_
multiline.asp
Variables
https://www.w3schools.com/php/php_variables.as
p
Constants:
https://www.w3schools.com/php/php_constants.as
p
Variables scope
https://www.w3schools.com/php/php_variables_sc
ope.asp
Global keyword
In PHP, the global keyword is used within a function to access a global
variable that is defined outside of the function. By default, variables declared
inside a function are local to that function. To use a global variable within a
function, you must explicitly declare it as global.