This document provides an overview of PHP, including what PHP is, how PHP scripts work, embedding PHP in web pages, variables, operators, control structures, arrays, functions, and forms. Some key points covered include: - PHP is a server-side scripting language commonly used for web development. PHP code is embedded within HTML and executed on the server to produce dynamic web page content. - PHP scripts typically have a .php file extension and use <?php ?> tags. Code within the tags is executed by the server and the results are returned to the browser. - Variables, constants, operators, and control structures like if/else statements allow PHP to dynamically output content. Arrays and multid
Overview of PHP, its significance, and use in dynamic content creation.
PHP as a server-side scripting language, syntax, and how scripts are processed.
Embedding PHP in HTML and the process to execute a PHP file on a server.
Types of literals (strings, numbers, booleans) and basic functions to display data.
Definitions and usage of variables, including variable assignments and naming conventions.
Definition of constants and various operators (arithmetic, logical, comparison).
Introduction to control structures like if, loops, including examples.Creating and using arrays, including multidimensional arrays and traversing arrays.
Different embedding styles for PHP within HTML.
Defining functions, built-in functions, and using arguments.
Call by value, call by reference, normal scope, and global scope.Introduction to PHP superglobal variables including $_SERVER and $_GLOBALS.
Using $_REQUEST and $_GET variables for form processing and submissions.
Best practices for validating form data in PHP.
List of useful links and resources for PHP developers.
PHPWhat can PHPdo? What is a PHP File? Why PHP? Mrs .C.Santhiya Assistant Professor TCE,Madurai
2.
Background PHP isserver side scripting system. PHP stands for "PHP: Hypertext Preprocessor“ Syntax based on Perl, Java, and C Very good for creating dynamic content Powerful, but somewhat risky! If you want to focus on one system for dynamic content, this is a good one to choose
3.
PHP Scripts Typicallyfile ends in .php--this is set by the web server configuration Separated in files with the <?php ?> tag php commands can make up an entire file, or can be contained in html--this is a choice…. Program lines end in ";" or you get an error Server recognizes embedded script and executes Result is passed to browser, source isn't visible <?php $myvar = "Hello World!"; echo $myvar;?>
4.
Two Ways You canembed sections of php inside html: <BODY> <P> <?php $myvar = "Hello World!"; echo $myvar;</P> </BODY> Or you can call html from php: <?php echo "<html><head><title>Howdy</title> … ?>
5.
Code: <?php echo "Hello world!"; ?> Runa php file http://www.wampserver.com Go to start & start wamp server Open browser & http://local host Put php file in www folder c://wamp/www http:///local host/filename.php
Literals All stringsmust be enclosed in single of doublequotes: ‘Hello’ or “Hello”. Numbers are not in enclosed in quotes: 1 or 45 or34.564 Booleans (true/false) can be written directly as true or false.
8.
Comments // This isa comment # This is also a comment /* This is a comment that is spread over multiple lines */
9.
Displaying Data There aretwo language constructs available todisplay data: print() and echo(). They can be used with or without brackets. Note that the data ‘displayed’ by PHP is actually parsed by your browser as HTML. View source to see actual output. <?php echo ‘Hello World!<br />’; echo(‘Hello World!<br />’); print ‘Hello World!<br />’; print(‘Hello World!<br />’); ?>
Variables: What arethey? labelled ‘places’ are called VARIABLES $ followed by variable name Case sensitive $variable differs from $Variable Stick to lower-case to be sure! Name must started with a letter or an underscore Followed by any number of letters, numbers and underscores <?php $name = ‘Phil’; $age = 23; echo $name; echo ’ is ‘; echo $age; // Phil is 23 ?>
12.
Variables: What arethey? Assigned by value $foo = "Bob"; $bar = $foo; Assigned by reference, this links vars $bar = &$foo Some are preassigned, server and env vars For example, there are PHP vars, eg. PHP_SELF, HTTP_GET_VARS,etc
13.
Constants Constants (unchangeablevariables) can also be defined. Each constant is given a name (note no preceding dollar is applied here). By convention, constant names are usually in UPPERCASE <?php define(‘NAME’,‘Phil’); define(‘AGE’,23); echo NAME; echo ’ is ‘; echo AGE; // Phil is 23 ?>
14.
Operators Arithmetic (+, -,*, /, %) and String (.)Arithmetic (+, -, *, /, %) and String (.) Assignment (=) and combined assignmentAssignment (=) and combined assignment $a = 3; $a += 5; // sets $a to 8; $b = "Hello "; $b .= "There!"; // sets $b to "Hello There!"; Bitwise (&, |, ^, ~, <<, >>)Bitwise (&, |, ^, ~, <<, >>) $a ^ $b ~ $a Comparison (==, ===, !=, !==, <, >, <=, >=)Comparison (==, ===, !=, !==, <, >, <=, >=) Error Control (@)Error Control (@) Execution (` is similar to the shell_exec() function)Execution (` is similar to the shell_exec() function) Incrementing/DecrementingIncrementing/Decrementing
15.
Logical $a and $bAnd True if both $a and $b are true. $a or $b Or True if either $a or $b is true. $a xor $b Xor True if either $a or $b is true, but not both. ! $a Not True if $a is not true. $a && $b And True if both $a and $b are true. ++$a (Increments by one, then returns++$a (Increments by one, then returns $a.)$a.) $a++ (Returns $a, then increments $a$a++ (Returns $a, then increments $a by one.)by one.) --$a--$a (Decrements $a by one, then(Decrements $a by one, then returns $a.)returns $a.) $a--$a-- (Returns $a, then decrements $a(Returns $a, then decrements $a by one.)by one.)