Introduction to PHP Basics
Introduction to PHP Basics
to PHP Basics
A QUICK INFORMATION GUIDE
Objectives
STUDENTS WILL LEARN THE FUNDAMENTALS OF
PHP, INCLUDING SYNTAX, VARIABLES, AND BASIC
FUNCTIONS, AND WILL CREATE A SIMPLE DYNAMIC
WEB PAGE USING PHP.
Materials Needed:
·Computers with internet
access
What is PHP?
1. 2. 3. 4. 5.
DYNAMIC FORM DATABASE SESSION FILE
CONTENT HANDLING INTERACTION MANAGEMENT OPERATIONS
GENERATION
PHP can generate It can collect data from PHP can interact with It can manage user PHP can create, open, read,
dynamic page content, forms, process it, and various databases like sessions, which is write, delete, and close files
allowing websites to store it in databases, MySQL, PostgreSQL, crucial for maintaining on the server, which is
display different making it essential for and Oracle, enabling user state and data useful for tasks like file
content based on user creating interactive the creation of data- across multiple pages uploads and downloads1.
interactions or other web applications. driven websites. (e.g., user login Security: PHP includes
variables. systems). features for encrypting data
and managing user access,
helping to secure web
applications.
The difference between client-side and server-side
scripting.
-Client-Side Scripting
Execution Location: Runs on the user’s browser.
Languages Used: Commonly uses HTML, CSS, and JavaScript.
Purpose: Enhances user interfaces and interactions directly in the browser without needing to
communicate with the server for every action.
Visibility: Source code is visible to the user.
Performance: Can reduce load on the server by handling tasks like form validation, animations, and
dynamic content updates on the client side.
Security: Less secure since the code is exposed to the user.
Examples: Validating form inputs, creating interactive elements like sliders and carousels, and updating
content dynamically without refreshing the page.
-Server-Side Scripting
Execution Location: Runs on the web server.
Languages Used: Commonly uses PHP, Python, Ruby, Java, and Node.js.
Purpose: Handles data processing, database interactions, and dynamic page generation on the server.
Visibility: Source code is not visible to the user; only the output (HTML) is sent to the user’s browser.
Performance: Can handle complex tasks and heavy computations, but may increase server load.
Security: More secure as the code and data processing happen on the server.
Examples: Managing user authentication, accessing and manipulating databases, and generating dynamic
content based on user requests.
-Key Differences
Execution: Client-side scripts run on the user’s device, while server-side scripts run on the server.
Visibility: Client-side code is visible to users, whereas server-side code is hidden.
Interactivity: Client-side scripting allows for more immediate interactivity without server communication while
server-side scripting is essential for tasks requiring server resources and data.
Brief history and current
use of PHP in the industry.
Learning sessions are now conducted online in 95% of schools in the world.
-PHP, originally created by Rasmus Lerdorf in 1994, started as a set of Common Gateway
Interface (CGI) binaries written in C to track visits to his online resume. Initially named
“Personal Home Page Tools” (PHP Tools), it evolved significantly over time. By 1995,
Lerdorf had released the source code to the public, allowing for community contributions
and improvements. This led to the development of PHP/FI (Forms Interpreter), which
included basic functionality for dynamic web applications.
-In 1997, PHP 3.0 was released, marking a significant milestone as it introduced a more
robust and extensible architecture. PHP 4.0, released in 2000, brought the Zend Engine,
which greatly improved performance. PHP 5.0, released in 2004, introduced object-oriented
programming features. The language continued to evolve, with PHP 7.0 in 2015 bringing
major performance enhancements and PHP 8.0 in 2020 introducing the Just-In-Time (JIT)
compiler.
Current Use of PHP in
22.1%
the Industry
DESPITE THE EMERGENCE OF NUMEROUS NEW PROGRAMMING
LANGUAGES AND FRAMEWORKS, PHP REMAINS A DOMINANT FORCE IN
WEB DEVELOPMENT. AS OF 2023, PHP IS USED BY APPROXIMATELY
77.5% OF ALL WEBSITES WHOSE SERVER-SIDE PROGRAMMING
LANGUAGE IS KNOWN. THIS INCLUDES MAJOR PLATFORMS LIKE
77.9%
FACEBOOK, WORDPRESS, AND WIKIPEDIA.
PHP is particularly popular for developing content management systems (CMS) such as WordPress, Drupal, and
Joomla. Its ease of use, extensive documentation, and large community support make it a preferred choice for
many developers. Additionally, PHP’s compatibility with various databases and its ability to run on almost any
server and operating system contribute to its widespread adoption.
PHP continues to be relevant due to its constant updates and improvements, ensuring it meets modern web
development needs. The introduction of PHP 8.0 with the JIT compiler has further enhanced its performance,
making it competitive with newer languages.
Lesson Outline
2. Setting up the Environment
index.php: The main entry point config.php: Configuration htaccess: Apache configuration
for your application. settings for your project. file (if you’re using Apache).
Directories
2 EXAMPLE STRUCTURE
assets/: Contains static files like CSS, JavaScript, and images.
css/: Stylesheets.
js/: JavaScript files.
images/: Image files.
Basic PHP syntax: <?php ... ? Echoing output: echo and Comments in PHP: single-line (//)
>. print. and multi-line (/* ... */).
4
HTML
IS THE STANDARD MARKUP LANGUAGE
FOR WEB PAGES.
WITH HTML YOU CAN CREATE YOUR
OWN WEBSITE.
HTML IS EASY TO LEARN - YOU WILL
ENJOY IT!
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
CSS
IS THE LANGUAGE WE USE TO STYLE AN
HTML DOCUMENT.
CSS DESCRIBES HOW HTML ELEMENTS
SHOULD BE DISPLAYED.
THIS TUTORIAL WILL TEACH YOU CSS
FROM BASIC TO ADVANCED.
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
JavaScript
IT IS THE WORLD'S MOST POPULAR PROGRAMMING LANGUAGE.
PHP Installation
TO START USING PHP, YOU CAN:
JUST CREATE SOME .PHP FILES, PLACE THEM IN YOUR WEB DIRECTORY, AND THE SERVER
WILL AUTOMATICALLY PARSE THEM FOR YOU.
YOU DO NOT NEED TO COMPILE ANYTHING OR INSTALL ANY EXTRA TOOLS.
BECAUSE PHP IS FREE, MOST WEB HOSTS OFFER PHP SUPPORT.
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
PHP Syntax
A PHP SCRIPT IS EXECUTED ON THE SERVER, AND THE PLAIN HTML RESULT IS SENT BACK
TO THE BROWSER.
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
EXAMPLE
ECHO IS THE SAME AS ECHO:
EXAMPLE
$COLOR IS NOT SAME AS $COLOR:
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
PHP Comments
A COMMENT IN PHP CODE IS A LINE THAT IS NOT EXECUTED AS A PART OF THE PROGRAM.
ITS ONLY PURPOSE IS TO BE READ BY SOMEONE WHO IS LOOKING AT THE CODE.
EXAMPLE
A COMMENT BEFORE THE CODE:
EXAMPLE
A COMMENT AT THE END OF A
LINE:
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
Multi-Line Comments
MULTI-LINE COMMENTS START WITH /* AND END WITH */.
ANY TEXT BETWEEN /* AND */ WILL BE IGNORED.
THE FOLLOWING EXAMPLE USES A MULTI-LINE COMMENT AS AN EXPLANATION:
EXAMPLE:
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
EXAMPLE
THE + 15 PART WILL BE IGNORED IN THE CALCULATION:
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
PHP Variables
VARIABLES ARE "CONTAINERS" FOR STORING INFORMATION.
CREATING (DECLARING) PHP VARIABLES
IN PHP, A VARIABLE STARTS WITH THE $ SIGN, FOLLOWED BY THE NAME OF THE VARIABLE:
IN THE EXAMPLE ABOVE, THE VARIABLE $X WILL HOLD THE VALUE 5, AND THE VARIABLE $Y WILL HOLD THE
VALUE "JOHN".
NOTE: WHEN YOU ASSIGN A TEXT VALUE TO A VARIABLE, PUT QUOTES AROUND THE VALUE.
NOTE: UNLIKE OTHER PROGRAMMING LANGUAGES, PHP HAS NO COMMAND FOR DECLARING A VARIABLE. IT IS
CREATED THE MOMENT YOU FIRST ASSIGN A VALUE TO IT.
BEFORE YOU CONTINUE YOU SHOULD HAVE A BASIC UNDERSTANDING OF THE FOLLOWING:
PHP Variables
A VARIABLE CAN HAVE A SHORT NAME (LIKE $X AND $Y) OR A MORE DESCRIPTIVE NAME ($AGE,
$CARNAME, $TOTAL_VOLUME).