SlideShare a Scribd company logo
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
PHP: Hypertext Preprocessor
• PHP is a server scripting language, and a
powerful tool for making dynamic and
interactive Web pages.
• PHP is a widely-used, free, and efficient
alternative to competitors such as Microsoft's
ASP.
• <?php
// PHP code goes here
?>
• <!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
PHP variables
• <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
• A variable starts with the $ sign, followed by the
name of the variable
• A variable name must start with a letter or the
underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive
($age and $AGE are two different variables)
• <?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with
multiple parameters.";
?>
• <?php
$txt1 = "Learn PHP";
$txt2 = "Welcome";
$x = 5;
$y = 4;
print "<h2>" . $txt1 "</h2>";
print "Study PHP " . $txt2 "<br>";
print $x + $y;
?>
php is the most important programming language
Data types
• Integer
• Double
• String
• Boolean
php is the most important programming language
php is the most important programming language
<!DOCTYPE html>
<html>
<body>
<?php
echo strpos(“jsp php jstl php ","php");
?>
</body>
</html>
• <?php
$str = "Hello World!nn";
echo $str;
echo chop($str);
?>
• <?php
$str = "Hello World!";
echo $str . "<br>";
echo trim($str,"Hed!");
?>
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
If..elseif..else
<!DOCTYPE html>
<html>
<body>
<?php
$t = date("H");
echo "<p>The hour (of the server) is " . $t;
echo ", and will give the following message:</p>";
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
</body>
</html>
switch
<!DOCTYPE html>
<html>
<body>
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
</body>
</html>
while
<!DOCTYPE html>
<html>
<body>
<?php
$x = 0;
while($x <= 100) {
echo "The number is: $x <br>";
$x+=10;
}
?>
</body>
</html>
Do…while
<!DOCTYPE html>
<html>
<body>
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
</body>
</html>
For loop
<!DOCTYPE html>
<html>
<body>
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
</body>
</html>
foreach
<!DOCTYPE html>
<html>
<body>
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
</body>
</html>
php is the most important programming language
php is the most important programming language
php is the most important programming language
Regular Expression
• ereg- it recognizes Portable Operating system
Interface extended regular expression(POSIX)
• preg- Perl compatible regular
expressions(PCRE)
Regular Expression
<!DOCTYPE html>
<html>
<body>
<?php
$str = "Visit College";
$pattern = "/college/i";
echo preg_match($pattern, $str);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<?php
$str = "Visit College";
$pattern = "/college/i";
echo preg_match($pattern, $str);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<?php
$str = "Visit Microsoft!";
$pattern = "/microsoft/i";
echo preg_replace($pattern, “sun", $str);
?>
</body>
</html>
Regular expression example
php is the most important programming language
php is the most important programming language
• In PHP form data values are directly available as
implicit variables whose names match the names
of the corresponding form elements.
• This is know as implicit access
• Many web servers not allow this, because of
security problem
• Implicit arrays – these have keys that match the
form element names and values that were input
by the clients
• $_POST[],$_GET[]
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
• A cookie is often used to identify a user. A
cookie is a small file that the server embeds
on the user's computer. Each time the same
computer requests a page with a browser, it
will send the cookie too. With PHP, you can
both create and retrieve cookie values.
• A cookie is created with
the setcookie() function.
• $_COOKIE
• SESSION COOKIE
• PERSISTENT COOKIE
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
php is the most important programming language
• <!DOCTYPE html>
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_value];
}
?>
<p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p>
</body>
</html>
Delete cookie
• <!DOCTYPE html>
<?php
// set the expiration date to one hour ago
setcookie("user", "", time() - 3600);
?>
<html>
<body>
<?php
echo "Cookie 'user' is deleted.";
?>
</body>
</html>
Enabled or not
• <!DOCTYPE html>
<?php
setcookie("test_cookie", "test", time() + 3600, '/');
?>
<html>
<body>
<?php
if(count($_COOKIE) > 0) {
echo "Cookies are enabled.";
} else {
echo "Cookies are disabled.";
}
?>
</body>
</html>
Mysql connect
• <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>
• <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
• <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>

More Related Content

Similar to php is the most important programming language (20)

PPT
Php basic for vit university
Mandakini Kumari
 
PDF
Php summary
Michelle Darling
 
PPTX
Php basics
Jamshid Hashimi
 
PDF
PHP tips and tricks
Damien Seguy
 
PPTX
PHP language presentation
Annujj Agrawaal
 
PDF
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
PPTX
Ch1(introduction to php)
Chhom Karath
 
PDF
Tutorial_4_PHP
tutorialsruby
 
PDF
Tutorial_4_PHP
tutorialsruby
 
PDF
Tutorial_4_PHP
tutorialsruby
 
PDF
Tutorial_4_PHP
tutorialsruby
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PDF
Php tips-and-tricks4128
PrinceGuru MS
 
PPT
Php introduction
Osama Ghandour Geris
 
PPT
php 1
tumetr1
 
PPTX
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
PPT
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
PPT
Php with my sql
husnara mohammad
 
Php basic for vit university
Mandakini Kumari
 
Php summary
Michelle Darling
 
Php basics
Jamshid Hashimi
 
PHP tips and tricks
Damien Seguy
 
PHP language presentation
Annujj Agrawaal
 
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
Ch1(introduction to php)
Chhom Karath
 
Tutorial_4_PHP
tutorialsruby
 
Tutorial_4_PHP
tutorialsruby
 
Tutorial_4_PHP
tutorialsruby
 
Tutorial_4_PHP
tutorialsruby
 
PHP Hypertext Preprocessor
adeel990
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php tips-and-tricks4128
PrinceGuru MS
 
Php introduction
Osama Ghandour Geris
 
php 1
tumetr1
 
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
Php with my sql
husnara mohammad
 

Recently uploaded (20)

PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
Difference between write and update in odoo 18
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Horarios de distribución de agua en julio
pegazohn1978
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
epi editorial commitee meeting presentation
MIPLM
 
Difference between write and update in odoo 18
Celine George
 
Ad

php is the most important programming language

  • 10. PHP: Hypertext Preprocessor • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. • PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
  • 11. • <?php // PHP code goes here ?>
  • 12. • <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
  • 13. PHP variables • <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?>
  • 14. • A variable starts with the $ sign, followed by the name of the variable • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive ($age and $AGE are two different variables)
  • 15. • <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?>
  • 16. • <?php $txt1 = "Learn PHP"; $txt2 = "Welcome"; $x = 5; $y = 4; print "<h2>" . $txt1 "</h2>"; print "Study PHP " . $txt2 "<br>"; print $x + $y; ?>
  • 18. Data types • Integer • Double • String • Boolean
  • 21. <!DOCTYPE html> <html> <body> <?php echo strpos(“jsp php jstl php ","php"); ?> </body> </html>
  • 22. • <?php $str = "Hello World!nn"; echo $str; echo chop($str); ?>
  • 23. • <?php $str = "Hello World!"; echo $str . "<br>"; echo trim($str,"Hed!"); ?>
  • 24. • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators
  • 25. If..elseif..else <!DOCTYPE html> <html> <body> <?php $t = date("H"); echo "<p>The hour (of the server) is " . $t; echo ", and will give the following message:</p>"; if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?> </body> </html>
  • 26. switch <!DOCTYPE html> <html> <body> <?php $favcolor = "red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; } ?> </body> </html>
  • 27. while <!DOCTYPE html> <html> <body> <?php $x = 0; while($x <= 100) { echo "The number is: $x <br>"; $x+=10; } ?> </body> </html>
  • 28. Do…while <!DOCTYPE html> <html> <body> <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?> </body> </html>
  • 29. For loop <!DOCTYPE html> <html> <body> <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?> </body> </html>
  • 30. foreach <!DOCTYPE html> <html> <body> <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?> </body> </html>
  • 34. Regular Expression • ereg- it recognizes Portable Operating system Interface extended regular expression(POSIX) • preg- Perl compatible regular expressions(PCRE)
  • 35. Regular Expression <!DOCTYPE html> <html> <body> <?php $str = "Visit College"; $pattern = "/college/i"; echo preg_match($pattern, $str); ?> </body> </html>
  • 36. <!DOCTYPE html> <html> <body> <?php $str = "Visit College"; $pattern = "/college/i"; echo preg_match($pattern, $str); ?> </body> </html>
  • 37. <!DOCTYPE html> <html> <body> <?php $str = "Visit Microsoft!"; $pattern = "/microsoft/i"; echo preg_replace($pattern, “sun", $str); ?> </body> </html>
  • 41. • In PHP form data values are directly available as implicit variables whose names match the names of the corresponding form elements. • This is know as implicit access • Many web servers not allow this, because of security problem • Implicit arrays – these have keys that match the form element names and values that were input by the clients • $_POST[],$_GET[]
  • 53. • A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
  • 54. • A cookie is created with the setcookie() function. • $_COOKIE • SESSION COOKIE • PERSISTENT COOKIE
  • 61. • <!DOCTYPE html> <?php $cookie_name = "user"; $cookie_value = "John Doe"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day ?> <html> <body> <?php if(!isset($_COOKIE[$cookie_name])) { echo "Cookie named '" . $cookie_name . "' is not set!"; } else { echo "Cookie '" . $cookie_name . "' is set!<br>"; echo "Value is: " . $_COOKIE[$cookie_value]; } ?> <p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p> </body> </html>
  • 62. Delete cookie • <!DOCTYPE html> <?php // set the expiration date to one hour ago setcookie("user", "", time() - 3600); ?> <html> <body> <?php echo "Cookie 'user' is deleted."; ?> </body> </html>
  • 63. Enabled or not • <!DOCTYPE html> <?php setcookie("test_cookie", "test", time() + 3600, '/'); ?> <html> <body> <?php if(count($_COOKIE) > 0) { echo "Cookies are enabled."; } else { echo "Cookies are disabled."; } ?> </body> </html>
  • 64. Mysql connect • <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // sql to create table $sql = "CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP )"; if ($conn->query($sql) === TRUE) { echo "Table MyGuests created successfully"; } else { echo "Error creating table: " . $conn->error; } $conn->close(); ?>
  • 65. • <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', '[email protected]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
  • 66. • <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?>