php is the most important programming language

padmanabanm47 11 views 66 slides May 27, 2024
Slide 1
Slide 1 of 66
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66

About This Presentation

Ph0


Slide Content

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; ?>

Data types Integer Double String Boolean

<!DOCTYPE html> <html> <body> <?php echo strpos (“ jsp php jstl php ","php"); ?> </body> </html>

<?php $ str = "Hello World!\n\n"; 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>

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

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[]

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

<!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', '[email protected]')"; 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(); ?>
Tags