The document provides information about PHP (Hypertext Preprocessor), an open-source scripting language commonly used for web development. It discusses that PHP code is embedded within HTML and is executed on the server-side to generate dynamic web page content. The document outlines PHP's syntax, variables, data types, output functions, expressions, and control structures. It provides examples of comments, variables, basic types like integers and strings, and operators. Overall, the document serves as an introduction to key concepts in PHP.
PHP (Hypertext Processor) is a general-purpose scripting language and interpreter that is freely available and widely used for web development. The language is used primarily for server-side scripting, although it can also be used for command-line scripting and, to a limited degree, desktop applications.
PHP is a programming language used to script websites that are dynamic and interactive. You'll find it in various types of web applications, from e-commerce websites to CRM systems like HubSpot and Salesforce. The term PHP stands for PHP Hypertext Preprocessor.
The full form of PHP is Hypertext Preprocessor. It was abbreviated previously as Personal Home Page. It is a programming language widely used to build web applications or websites. It is the server-side scripting language encoded with HTML to develop Dynamic website, Static website or Web applications.
PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types that can be categorized further in 3 types: Scalar Types (predefined) Compound Types (user-defined) Special Types.
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
PHP (Hypertext Processor) is a general-purpose scripting language and interpreter that is freely available and widely used for web development. The language is used primarily for server-side scripting, although it can also be used for command-line scripting and, to a limited degree, desktop applications.
PHP is a programming language used to script websites that are dynamic and interactive. You'll find it in various types of web applications, from e-commerce websites to CRM systems like HubSpot and Salesforce. The term PHP stands for PHP Hypertext Preprocessor.
The full form of PHP is Hypertext Preprocessor. It was abbreviated previously as Personal Home Page. It is a programming language widely used to build web applications or websites. It is the server-side scripting language encoded with HTML to develop Dynamic website, Static website or Web applications.
PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types that can be categorized further in 3 types: Scalar Types (predefined) Compound Types (user-defined) Special Types.
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
Introduction to PHP: Declaring variables, data types, arrays, strings, operators, expressions, control structures, functions, Handling sessions and cookies
File Handling in PHP: File operations like opening, closing, reading, writing appending, deleting etc.
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
Introduction to PHP: Declaring variables, data types, arrays, strings, operators, expressions, control structures, functions, Handling sessions and cookies
File Handling in PHP: File operations like opening, closing, reading, writing appending, deleting etc.
Similar to Basics of PHP by Dr.C.R.Dhivyaa Kongu Engineering College (20)
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...Dhivyaa C.R
Interprocess Communication: The API for the Internet Protocols – External data representation and marshalling – Client– server communication – Group communication. Distributed Objects – Communication between distributed objects – Remote procedure call.
Democratizing Fuzzing at Scale by Abhishek Aryaabh.arya
Presented at NUS: Fuzzing and Software Security Summer School 2024
This keynote talks about the democratization of fuzzing at scale, highlighting the collaboration between open source communities, academia, and industry to advance the field of fuzzing. It delves into the history of fuzzing, the development of scalable fuzzing platforms, and the empowerment of community-driven research. The talk will further discuss recent advancements leveraging AI/ML and offer insights into the future evolution of the fuzzing landscape.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Quality defects in TMT Bars, Possible causes and Potential Solutions.PrashantGoswami42
Maintaining high-quality standards in the production of TMT bars is crucial for ensuring structural integrity in construction. Addressing common defects through careful monitoring, standardized processes, and advanced technology can significantly improve the quality of TMT bars. Continuous training and adherence to quality control measures will also play a pivotal role in minimizing these defects.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
2. Contents
PHP’s Syntax – Comments – Variables – Types in PHP – The Simple Types –
Doubles – Booleans – NULL – Strings – Output – Expressions – Branching –
Looping – Using Functions – User Defined Functions – Functions and Variable
Scope – Function Scope
3. What is PHP?
● PHP is the web development language written by and for web developers.
● PHP stands for PHP: Hypertext Preprocessor
● The product was originally named Personal Home Page
● PHP is a server-side scripting language, usually used to create web
applications in combination with a web server, such as Apache
● PHP is a widely-used, open source scripting language
● Embedded within PHP
● Develop dynamic web sites
● Easy integration with DB
● Cross-platform compatibility
4. PHP’s Syntax
● A PHP script can be placed anywhere in the document.
● A PHP script starts with <?php and ends with ?>:
<?php
// PHP code goes here
?>
● The default file extension for PHP files is ".php".
● A PHP file normally contains HTML tags, and some PHP scripting code.
6. PHP is whitespace insensitive
For example, each of the following PHP statements that assigns the sum
of 2 + 2 to the variable
$four is equivalent:
$four = 2 + 2; // single spaces
$four <tab>=<tab>2<tab>+<tab>2 ; // spaces and tabs
$four =
2
+
2; // multiple lines
7. PHP is sometimes case sensitive
In particular, all variables are case sensitive.
If you embed the following code in an HTML page:
<?php
$capital = 67;
print(“Variable capital is $capital<BR>”);
print(“Variable CaPiTaL is $CaPiTaL<BR>”);
?>
The output you will see is:
Variable capital is 67
Variable CaPiTaL is
8. Statements are expressions terminated by semicolons
● A statement in PHP is any expression that is followed by a semicolon (;).
● Example:
$greeting = “Welcome to PHP!”;
9. Comments
A comment is the portion of a program that exists only for the human reader.
● C-style multiline comments
○ The multiline style of commenting is the same as in C: A comment starts with the
character pair /* and terminates with the character pair */.
○ For example: /* This is a comment in PHP */
● Single-line comments: # and //
○ PHP supports two different ways of commenting to the end of a given line: one
inherited from C++ and Java and the other from Perl and shell scripts.
○ The shell-script-style comment starts with a pound sign, whereas the C++ style
comment starts with two forward slashes.
○ Example: # This is a comment
// This is a comment too
10. Variables
● Variables are "containers" for storing information.
● All variables in PHP are denoted with a leading dollar sign ($).The value of a
variable is the value of its most recent assignment.
● Variables are assigned with the = operator, with the variable on the left-hand side
and the
● expression to be evaluated on the right.
● Variables can, but do not need, to be declared before assignment.
● Variables have no intrinsic type other than the type of their current value.
● Variables used before they are assigned have default values.
11. ● PHP variables are Perl-like
○ All variables in PHP start with a leading $ sign just like scalar variables in the
Perl scripting language
● Declaring variables (or not)
○ In PHP, types are associated with values rather than variables, no such
declaration is necessary
○ The first step in using a variable is to assign it a value.
● Assigning variables
○ Variable assignment is simple — just write the variable name, and add a single
equal sign (=); then add the expression that you want to assign to that
variable: $pi = 3 + 0.14159;.
12. ● Reassigning variables
○ There is no interesting distinction in PHP between assigning a variable for the
first time and changing its value later
○ Example :$my_num_var = “This should be a number – hope it’s reassigned”;
$my_num_var = 5;
● Unassigned variables
○ In a situation where a number is expected, a number will be produced, and
this works similarly with character strings.
○ In any context that treats a variable as a number, an unassigned variable will
be evaluated as 0; in any context that expects a string value, an unassigned
variable will be the empty string
13. ● Variable scope
○ In PHP, variables can be declared anywhere in the script.
○ The scope of a variable is the part of the script where the variable can be
referenced/used.
○ PHP has two different variable scopes:
● Local
A variable declared within a function has a LOCAL SCOPE and can
only be accessed within that function
● Global
A variable declared outside a function has a GLOBAL SCOPE and can
only be accessed outside a function
14. Types in PHP
● PHP’s type system is simple, streamlined, and flexible, and it insulates the
programmer from low-level details.
● PHP makes it easy not to worry too much about typing of variables and values, both
because it does not require variables to be typed and because it handles a lot of
type conversions
No variable type declarations
● The type of a variable does not need to be declared in advance
Automatic type conversion
● PHP does a good job of automatically converting types when necessary
● $pi = 3 + 0.14159;
● The result of the expression is a floating-point (double) number, with the integer
3 implicitly converted into floating point before the addition is performed.
15. Type Summary
● Integers are whole numbers, without a decimal point, like 495.
● Doubles are floating-point numbers, like 3.14159 or 49.0.
● Booleans have only two possible values: TRUE and FALSE.
● NULL is a special type that only has one value: NULL.
● Strings are sequences of characters, like ‘PHP 4.0 supports string operations.’
● Arrays are named and indexed collections of other values.
● Objects are instances of programmer-defined classes, which can package up both
other kinds of values and functions that are specific to the class.
● Resources are special variables that hold references to resources external to PHP
(such as database connections).
16. The Simple Types
● The most of the simple types in PHP (integers, doubles, Booleans, NULL, and
strings) should be familiar to those with programming experience
Integers
● Integers are the simplest type — they correspond to simple whole numbers,
both positive and negative.
● Integers can be assigned to variables, or they can be used in expressions, like
this:
○ $int_var = 12345;
○ $another_int = -12345 + 12345;
17. The Simple Types
Doubles
● Doubles are floating-point numbers, such as:
○ $first_double = 123.456;
Booleans
● Booleans are true-or-false values, which are used in control constructs like
the testing portion of an if statement.
NULL
● The type NULL has only one possible value, which is the value NULL.
● To give a variable the NULL value, simply assign it like this:
● $my_var = NULL;
18. The Simple Types
Strings
● Strings are character sequences, as in the following:
$string_1 = “This is a string in double quotes.”;
● Everything inside quotes, single (‘ ‘) and double (” “) in PHP is treated as a string.
Single-quote strings:This type of string does not process special characters inside
quotes.
<?php
// single-quote strings
$site = 'GeeksforGeeks';
echo 'Welcome to $site';?>
Output: Welcome to $site
19. The Simple Types
Double-quote strings
Unlike single-quote strings, double-quote strings in PHP are capable of processing
special characters.
<?php
// double-quote strings
echo "Welcome to GeeksforGeeks n";
$site = "GeeksforGeeks";
echo "Welcome to $site";
?>
Output: Welcome to GeeksforGeeks
20. Output
Echo and print
● The two most basic constructs for printing to output are echo and print
Echo
● The echo statement can be used with or without parentheses: echo or echo().
● The simplest use of echo is to print a string as argument,
● for example:
○ echo “This will print in the user’s browser window.”;
○ echo "This ", "string ", "was ", "made ", "with multiple parameters.";
● Or equivalently:
○ echo(“This will print in the user’s browser window.”);
21. Output
Print
● The print statement can be used with or without parentheses: print or
print().
● for example:
○ print "Hello world!<br>";
○ print "I'm about to learn PHP!";
● Or equivalently:
○ print ("Hello world!<br>");
○ print ("I'm about to learn PHP!");
22. Output
Difference between Echo and Print
● echo has no return value while print has a return value of 1 so it can be
used in expressions.
● echo can take multiple parameters (although such usage is rare) while
print can take one argument. echo is marginally faster than print.
23. Expressions
Boolean Expressions
● Every control structure in this chapter has two distinct parts:
○ the test (which determines which part of the rest of the structure executes), and
○ the dependent code itself (whether separate branches or the body of a loop).
● Tests work by evaluating a Boolean expression, an expression with a
result treated as either true or false.
Boolean constants
● The simplest kind of expression is a simple value, and the simplest
Boolean values are the constants TRUE and FALSE
24. Logical operators
● Logical operators combine other logical (aka Boolean) values to produce new
Boolean values.
● The standard logical operations (and, or, not, and exclusive-or) are supported
by PHP
25. Precedence of logical operators
● The logical operators listed in declining order of precedence are: !, &&, ||,
and, xor, or
● Actually, and, xor, and or have much lower precedence than the others, so
that the assignment operator (=) binds more tightly than and but less tightly
than &&.
Comparison operators
26. Operator precedence
Comparison operators have higher precedence than Boolean operators
String comparison
The comparison operators may be used to compare strings as well as numbers
Ternary operator
Its job is to take three expressions and use the truth value of the first
expression to decide which of the other two expressions to evaluate and return.
The syntax looks like: testExpression ? yesExpression : noExpression
27. Operator precedence
Comparison operators have higher precedence than Boolean operators
String comparison
The comparison operators may be used to compare strings as well as numbers
Ternary operator
Its job is to take three expressions and use the truth value of the first
expression to decide which of the other two expressions to evaluate and return.
The syntax looks like: testExpression ? yesExpression : noExpression
29. Branching
● The two main structures for branching are if and switch.
● Switch is a useful alternative for certain situations where you want
multiple possible branches based on a single value
If-else
if (test)
statement-1
else
statement-2
<html>
<body>
<?php
$a=10;
$b=20;
if ($a > $b) {
echo "a is greater";
} else {
echo "b is greater";
}
?>
</body>
</html>
30. Switch
For a specific kind of multiway branching, the switch construct can be useful.
switch(expression)
{
case value-1:
statement-1;
statement-2;
...
[break;]
case value-2:
statement-3;
statement-4;
...
[break;]
...
[default:
default-statement;]
}
31. <!DOCTYPE html>
<html>
<body>
<?php
$day =3;
switch ($day) {
case 0:
echo "Sunday";
break;
case 1:
echo "Monday";
break;
case 2:
echo "tuesday";
break;
case 3:
echo "wednesday";
break;
case 4:
echo "thursday";
break;
case 5:
echo "friday";
break;
case 6:
echo "saturday";
break;
default:
echo "wrong option!";
}
?>
</body>
</html>
32. Looping
Loops are used to execute the same block of code again and again, as long
as a certain condition is true.
In PHP, we have the following loop types:
● while - loops through a block of code as long as the specified condition
is true
● do...while - loops through a block of code once, and then repeats the
loop as long as the specified condition is true
● for - loops through a block of code a specified number of times
33. While
The simplest PHP looping construct is while, which has the following syntax:
while (condition)
Statement
Example:
<html>
<body>
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
</body>
</html>
34. doWhile
The do-while construct is similar to while, except that the test happens at the end of the loop.
The syntax is:
do statement
while (expression);
Example:
<html>
<body>
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
</body>
</html>
35. For
The most complicated looping construct is for, which has the following syntax:
for (initial-expression;
termination-check;
loop-end-expression)
statement
Example:
<html>
<body>
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
</body>
</html>
36. Break and continue
● The break command exits the innermost loop construct that contains it.
● The continue command skips to the end of the current iteration of the innermost loop
that contains it.
Break:
<html>
<body>
<?php
for ($x = 0; $x < 10; $x++) {
if ($x == 4) {
break;
}
echo "The number is: $x <br>";
}
?>
</body>
</html>
Continue
<html>
<body>
<?php
for ($x = 0; $x < 10; $x++) {
if ($x == 4) {
continue;
}
echo "The number is: $x <br>";
}
?>
</body>
</html>
37. Using Functions
● A function is a way of wrapping up a chunk of code and giving that chunk a name, so that you
can use that chunk later in just one line of code. Functions are most useful when you will be
using the code in more than one place
The basic syntax for using (or calling) a function is:
function_name(expression_1, expression_2, ..., expression_n)
Built-in PHP functions
● PHP has over 1000 built-in functions that can be called directly, from within a script, to
perform a specific task.
sqrt(9); // square root function, evaluates to 3
rand(10, 10 + 10); // random number between 10 and 20
strlen(“This has 22 characters”); // returns the number 22
pi(); // returns the approximate value of pi
38. User Defined Functions
It is possible to create your own functions.
● A function is a block of statements that can be used repeatedly in a program.
● A function will not execute automatically when a page loads.
● A function will be executed by a call to the function.
Function definition syntax
function function-name ($argument-1, $argument-2, ..)
{
statement-1;
statement-2;
...}
39. That is, function definitions have four parts:
● The special word function
● The name that you want to give your function
● The function’s parameter list — dollar-sign variables separated by
commas
● The function body — a brace-enclosed set of statements
40. when a user-defined function is called is:
● PHP looks up the function by its name
● PHP substitutes the values of the calling arguments
● The statements in the body of the function are executed.
41. Example
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg();
?>
Addition of two numbers
<html>
<body>
<?php
$a=5;
$b=8;
function add($a,$b)
{
$c=$a+$b;
echo $c;
}
add($a,$b);
?>
</body>
</html>
42. Formal parameters versus actual parameters
● The Actual parameters are the values that are passed to the function when it is
invoked.
● The Formal Parameters are the variables defined by the function that receives
values when the function is called.
Argument number mismatches
What happens if you call a function with fewer arguments than appear in the definition,
or with more? As you might have come to expect by now, PHP handles this without
anything crashing, but it may print a warning depending on your settings for error
reporting.
43. Functions and Variable Scope
● The scope of a variable is defined as its range in the program under which it can
be accessed.
● In other words, "The scope of a variable is the portion of the program within
which it is defined and can be accessed."
PHP has three types of variable scopes:
1. Local variable
2. Global variable
3. Static variable
44. Local variable
● The variables that are declared within a function are called local variables for that
function.
● These local variables have their scope only in that particular function in which they
are declared.
● This means that these variables cannot be accessed outside the function, as they
have local scope.
45. Example:
<?php
function localvar()
{
$num = 45; //local variable
echo "Local variable declared inside the function is: ". $num;
}
localvar();
?>
Output:Local variable declared inside the function is: 45
46. Global variable
● The global variables are the variables that are declared outside the function. These
variables can be accessed anywhere in the program.
● To access the global variable within a function, use the GLOBAL keyword before the
variable.
● However, these variables can be directly accessed or used outside the function without
any keyword. Therefore there is no need to use any keyword to access a global variable
outside the function.
48. Static variable
● It is a feature of PHP to delete the variable, once it completes its execution
and memory is freed. Sometimes we need to store a variable even after
completion of function execution. Therefore, another important feature of
variable scoping is static variable.
● We use the static keyword before the variable to define a variable, and this
variable is called as static variable.
● Static variables exist only in a local function, but it does not free its memory
after the program execution leaves the scope. Understand it with the help of
an example:
50. Function Scope
Include and Require
● It is possible to insert the content of one PHP file into another PHP file (before the server
executes it), with the include or require statement.
● Syntax:
include 'filename';
Or
require 'filename';
51. Include
A.php
<?php
$color='red';
$car='BMW';
?>
B.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php
include 'a.php';
echo "I have a $color $car.";
?>
</body>
</html>
Require
A.php
<?php
$color='red';
$car='BMW';
?>
B.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php
require 'a.php';
echo "I have a $color $car.";
?>
</body>
</html>
52. Include Versus Require
● Use require when the file is required by the application.
● Use include when the file is not required and application should continue when file
is not found.
Include(if file is not found)
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php include 'noFileExists.php';
echo "I have a $color $car.";
?>
</body>
</html>
Output:
Welcome to my home page!
I have a .
require(if file is not found)
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php require 'noFileExists.php';
echo "I have a $color $car.";
?>
</body>
</html>
Output:
Welcome to my home page!
53. Recursion
PHP also supports recursive function call like C/C++. In such case, we call current
function within function. It is also known as recursion.
Example:
<?php
function display($number) {
if($number<=5){
echo "$number <br/>";
display($number+1);
}
}
display(1);
?>
Output:
1
2
3
4
5