0% found this document useful (0 votes)
5 views

Php

Uploaded by

claytmpalonp
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Php

Uploaded by

claytmpalonp
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

PHP

INTRODUCTION TO PHP:
PHP (Hypertext Preprocessor) is a popular server-side scripting
language used for building dynamic websites and web
applications. It works behind the scenes on a web server to
generate content that is sent to a user's browser.
KEY FEATURES OF PHP:
Server-Side Execution: PHP runs on the server and sends the
result (like HTML) to the client’s browser.
Easy to Learn: PHP has simple syntax, making it beginner-friendly.
Dynamic Content: PHP can interact with databases to create
dynamic web pages (e.g., user profiles or search results).
Wide Compatibility: Works on different platforms (Windows,
Linux, macOS) and servers (Apache, etc.).
Free and Open Source: PHP is free to use and has a large
community for support.
WHAT CAN PHP DO?

Generate Dynamic Web Pages: Create content that changes


based on user interaction.
Work with Databases: Store and retrieve data, such as user
accounts or product catalogs.
Handle Forms: Process data submitted via forms, like login or
feedback forms.
File Operations: Create, open, read, write, and delete files on the
server.
Session Management: Track user activity, such as login sessions.
XAMPP:
XAMPP is a free and open-source software package that provides a
complete environment to set up a local web server on your
computer. It is widely used by developers to test and develop PHP-
based web applications locally before deploying them to a live
server.
KEY FEATURES OF XAMPP

Cross-Platform: Works on Windows, Linux, and macOS.


Components:
 Apache: Web server to host websites locally.
 MySQL/MariaDB: Database management system for storing data.
 PHP: Server-side scripting language for dynamic web pages.
 Perl: Another programming language included in XAMPP.

User-Friendly Interface: Easy to install, configure, and manage


components.
WHY WE USE XAMPP
Simplifies the setup of a local development environment.
Allows testing and debugging of web applications without needing
an internet connection.
Useful for learning and experimenting with web technologies like
PHP and MySQL.
CODE STRUCTURE:
<?php
Php code

?>
Store file with .php extension.
You can also place php code to an html file but store that file
with .php extension instead of html extension.
ECHO STATEMENT:
The echo statement is used to display strings, variables, HTML, or
other content in PHP scripts.
echo”Hello World”; OR
echo’Hello World’; OR
echo”Hello”, “World”;OR
echo (“hello”);
In PHP dot operator is used for concatenation, and comma is used for
displaying multiple values
echo”Hello”. “World”; echo”Hello”,“World”;
CONTINUE:
You can also place html code in echo statement but always put it in
single or double quotes.
echo”<b>Hello</b>”;
For integer values we don’t need to place inverted comas:
echo 50;
DIFFERENCE BETWEEN
ECHO AND PRINT
STATEMENT:
VARIABLE:
In php variable is declare with dollar sign e.g.
$a=“Ummul Mairaj”;
echo $a;
$b=18;
echo $b;
DATA TYPES IN PHP:
CONTINUE:
There is a function in PHP that tell us the data type of any variable
called var_dump() which basically return us two things data type
and value of variable.
$a="ummul mairaj";
var_dump($a);
Output will be:
string(12) "ummul mairaj“(12 is the numbers of characters in
string)
COMMENTS:
Comments in PHP are used to add notes or explanations within the
code, making it easier to understand and maintain. These
comments are ignored by the PHP interpreter and do not affect the
program's execution.
TYPES OF COMMENTS IN
PHP:
Single-line Comments: use// or # to write single-line comments.
// This is a single-line comment
# Another single-line comment
Multi-line Comments: Use /* */ to write comments that span
multiple lines.
/*This is a multi-line comment spanning more than one line.*/
CONSTANT VARIABLES:
Variable can store the latest value and only one value at a time.
When you want the value should not change then we use constant
variables. We use the following syntax for declaring constant
variable. We cant use $ sign with constant variable in php. Constant
varibles are global variables.
define (name,value,case-insensitive)
Example:
define("num",10);
echo num;
ARITHMETIC OPERATORS:
EXAMPLE:
<?php
$a=2;
$b=9;
$c=$a+$b;
echo $c;
$a++;
echo $a;
?>Perform other arithmetic operations.
ASSIGNMENT OPERATORS:
TASK:
Perform assignment operation.
COMPARISON OPERATORS:
EXAMPLE:
$e=10;
$f=10;
echo $e==$f;
In php if the result of condition is true it will return 1 if it if false
nothing will be printed.
IF STATEMENT:
<?php
$a=10;
$b=9;
if($a>$b)
{
echo "A is greater";
}
?>
LOGICAL OPERATORS:
EXAMPLE:
$age=18;
if ($age>=10and$age<=20)
{
echo"eligible";
}
Or
if (!($age==10))
echo"hello";
IF-ELSE:
<?php
$x=10;
if($x>11)
echo"X is greater";
else
echo"X is smaller";
?>
IF-ELSE-IF:
<!DOCTYPE html> $score = 85; // You can change the
<html> score to test different conditions
<head>
<title>PHP Else If Example</title> if ($score >= 90) {
</head> echo "Your grade is A.";
<body> } elseif ($score >= 80) {
<?php echo "Your grade is B.";
// A simple PHP program to check } elseif ($score >= 70) {
the grade of a student echo "Your grade is C.";
} elseif ($score >= 60) {
echo "Your grade is D.";
} else {
echo "Your grade is F.";
}
?>
</body>
</html>
SWITCH STATEMENT:
<!DOCTYPE html> case "Wednesday":
<html> echo "Midweek already!";
<head> break;
<title>PHP Switch Example</title> case "Thursday":
</head> echo "Almost the weekend!";
<body> break;
<?php case "Friday":
// Define a variable echo "Finally, it's Friday!";
$day = "Monday"; break;
case "Saturday":
// Use switch to check the day case "Sunday":
switch ($day) { echo "It's the weekend, relax!";
case "Monday": break;
echo "Start of the workweek!"; default:
break; echo "Invalid day!";
case "Tuesday": }
echo "Second day of the ?>
workweek!"; </body>
break; </html>

You might also like