0% found this document useful (0 votes)
19 views21 pages

Unit 1

The document provides an introduction to PHP, including what PHP is, what PHP files are, what PHP can do, and why PHP is used. It defines PHP as a widely-used open source scripting language that can be used to generate dynamic web page content, interact with databases, handle forms, and more. PHP files contain a combination of text, HTML, and PHP code. The document also provides an overview of basic web concepts like HTTP, URLs, websites, web servers, and HTML.

Uploaded by

Selvam Mano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views21 pages

Unit 1

The document provides an introduction to PHP, including what PHP is, what PHP files are, what PHP can do, and why PHP is used. It defines PHP as a widely-used open source scripting language that can be used to generate dynamic web page content, interact with databases, handle forms, and more. PHP files contain a combination of text, HTML, and PHP code. The document also provides an overview of basic web concepts like HTTP, URLs, websites, web servers, and HTML.

Uploaded by

Selvam Mano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 21

PAPER NAME: PHP SCRIPTING LANGUAGE UNIT: I

PAPER CODE: 17UCSS04 CLASS: III CS

CHAPTER I
INTRODUCTION
What is PHP?
 PHP is an acronym for "PHP Hypertext Preprocessor"
 PHP is a widely-used, open source scripting language
 PHP scripts are executed on the server
 PHP costs nothing, it is free to download and use
What is a PHP File?
 PHP files can contain text, HTML, CSS, JavaScript, and PHP code
 PHP code are executed on the server, and the result is returned to the browser as plain HTML
 PHP files have extension ".php"
What Can PHP Do?
 PHP can generate dynamic page content
 PHP can create, open, read, write, delete, and close files on the server
 PHP can collect form data
 PHP can send and receive cookies
 PHP can add, delete, modify data in your database
 PHP can restrict users to access some pages on your website
 PHP can encrypt data
With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies.
You can also output any text, such as XHTML and XML.
Why PHP?
 PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
 PHP is compatible with almost all servers used today (Apache, IIS, etc.)
 PHP supports a wide range of databases
 PHP is free.
 PHP is easy to learn and runs efficiently on the server side
Characteristics of PHP
1. Performance
 Scripts written in PHP execute faster than those written in other scripting languages, with many
independent standards putting the language ahead of competing alternatives like JSP, ASP.NET,
and Perl.

Department of Computer Science Page 1


 The PHP 5.0 engine was completely redesigned with an optimized memory manager to improve
performance, and is noticeably faster than previous versions.
2. Portability
 PHP is available for UNIX, Microsoft Windows, Mac OS, and OS/2, and PHP programs are
portable between platforms.
 As a result, a PHP application developed on, say, Windows will typically run on UNIX without any
significant issues.
 This ability to easily undertake cross-platform development is a valuable one, especially when
operating in a multiplatform corporate environment or when trying to address multiple market
segments.
3. Simplicity of Use
 PHP is an extremely stylish programming language.
 Its syntax is clear and consistent, and it comes with thorough documentation for the 5000+
functions included with the core distributions.
 PHP is preferred as a rapid prototyping tool for Web-based applications.
4. Open Source
 PHP is an open-source project—the language is developed by a worldwide team of volunteers who
make its source code freely available on the Web, and it may be used without payment of licensing
fees or investments in expensive hardware or software.
 This reduces software development costs without affecting either flexibility or reliability.
5. Third-Party Application Support
 One of PHP’s strengths has historically been its support for a wide range of different databases,
including MySQL, PostgreSQL, Oracle,

BASIC WEB CONCEPTS


What is Internet?
 The Internet is essentially a global network of computing resources.
 You can think about the Internet as a physical collection of routers and circuits as a set of shared
resources or even as an attitude about interconnecting and intercommunication.
 Some common definitions given in the past include:
 A network of networks based on the TCP/IP communications protocol.
 A community of people who use and develop those networks.
 A community of people who use and develop those networks.
Internet Based Services:
Some of the basic services available to Internet users are:

Department of Computer Science Page 2


 Email: A fast, easy, and inexpensive way to communicate with other Internet users around the
world.
 Telnet: Allows a user to log into a remote computer as though it were a local system.
 FTP: Allows a user to transfer virtually every kind of file that can be stored on a computer from
one Internet-connected computer to another.
 Use net news: A distributed bulletin board that offers a combination news and discussion service
on thousands of topics.
 World Wide Web (WWW): A hypertext interface to Internet information resources.
What is WWW?
 This stands for World Wide Web.
 A technical definition of the World Wide Web is : all the resources and users on the Internet that
are using the Hypertext Transfer Protocol (HTTP).
 A broader definition comes from the organization that Web inventor Tim Berners-Lee helped
found, the World Wide Web Consortium (W3C):
 The World Wide Web is the universe of network-accessible information, an embodiment of human
knowledge.
 In simple terms, The World Wide Web is a way of exchanging information between computers on
the Internet, tying them together into a vast collection of interactive multimedia resources.
What is HTTP?
 This stands for HyperText Transfer Protocol. This is the protocol being used to transfer hypertext
documents that makes the World Wide possible.
 A standard web address such as http://www.yahoo.com/ is called a URL and here the prefix http
indicates its protocol
What is URL?
 URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide
Web. A URL is the fundamental network identification for any resource connected to the web (e.g.,
hypertext pages, images, and sound files).
A URL will have the following format

protocol://hostname/other_information

 The protocol specifies how information from the link is transferred.


 The protocol used for web resources is HyperText Transfer Protocol (HTTP).
 Other protocols compatible with most web browsers include FTP, telnet, newsgroups, and Gopher.
 The protocol is followed by a colon, two slashes, and then the domain name.
 The domain name is the computer on which the resource is located.
 Links to particular files or subdirectories may be further specified after the domain name.

Department of Computer Science Page 3


 The directory names are separated by single forward slashes.
What is Website?
 Currently you are on our website http://www.tutorialspoint.com which is a collection of various
pages written in HTML markup language.
 This is a location on the web where people can find tutorials on latest technologies. Similar way
there is millions of websites available on the web.
 Each page available on the Website is called a web page and first page of any web site is called
home page for that site.
What is Web Server?
 Every Web site sits on a computer known as a Web server.
 This server is always connected to the internet.
 Every Web server that is connected to the Internet is given a unique address made up of a series of
four numbers between 0 and 256 separated by periods.
 for example, 68.178.157.132 or 68.122.35.127.
 When you register a Web address, also known as a domain name, such as tutorialspoint.com you
have to specify the IP address of the Web server that will host the site.
 We will see different type of Web servers in a separate chapter.
What is Web Browser?
 Web Browsers are software installed on your PC.
 To access the Web you need a web browsers, such as Netscape Navigator, Microsoft Internet
Explorer or Mozilla Firefox.
 Currently you must be using any sort of Web browser while you are naviating through my site
tutorialspoint.com.
 On the Web, when you navigate through pages of information this is commonly known as browsing
or surfing.
What is SMTP Server?
 This stands for Simple Mail Transfer Protocol Server.
 This server takes care of delivering emails from one server to another server.
 When you send an email to an email address, it is delivered to its recipient by a SMTP Server.
What is ISP?
 This stands for Internet Service Provider.
 They are the companies who provide you service in terms of internet connection to connect to the
internet.
 You will buy space on a Web Server from any Internet Service Provider.
 This space will be used to host your Web site.

Department of Computer Science Page 4


What is HTML?
 This stands for HyperText Markup Language.
 This is the language in which we write web pages for any Website. Even the page you are reading
right now is written in HTML.
 This is a subset of Standard Generalized Mark-Up Language (SGML) for electronic publishing, the
specific standard used for the World Wide Web.
What is Hyperlink?
 A hyperlink or simply a link is a selectable element in an electronic document that serves as an
access point to other electronic resources.
 Typically, you click the hyperlink to access the linked resource. Familiar hyperlinks include
buttons, icons, image maps, and clickable text links.
What is DNS?
 DNS stands for Domain Name System.
 When someone types in your domain name, www.example.com, your browser will ask the Domain
Name System to find the IP that hosts your site.
 When you register your domain name, your IP address should be put in a DNS along with your
domain name. Without doing it your domain name will not be functioning properly.

BASIC DEVELOPMENT CONCEPTS

When developing a PHP application for the Web, the typical approach is to embed PHP code into one or
more standard HTML documents using special “tags,” or delimiters. Here’s an example:
<html>
<head></head>
<body>
<div>
<?php echo sqrt(49); ?>
</div>
</body>
</html>
 From the preceding explanation, it should be clear that to get started building PHP applications,
your development environment must contain at least three components:
 A base operating system (OS) and server environment (usually Linux)
 A Web server (usually Apache on Linux or IIS on Windows) to intercept HTTP requests and either
serve them directly or pass them on to the PHP interpreter for execution

Department of Computer Science Page 5


 A PHP interpreter to parse and execute PHP code, and return the results to the Web server
 There’s also often a fourth optional but very useful component:
 A database engine (such as MySQL) that holds application data, accepts connections from the PHP
layer, and modifies or retrieves data from the database
 An important corollary of this approach is that the PHP code is executed on the server, and not on
the client browser.
 This allows Web developers to write program code that is completely independent of, and thus
impervious to, browser quirks—an important advantage over client-side scripting languages, such as
JavaScript, which often require complex logic to account for browser-specific differences.
 Further, because the code is all executed on the server and only the output is sent to the client, it is
impossible for users to see the source code of your PHP program—an important security advantage
over languages like JavaScript.

CREATING FIRST PHP SCRIPTS


Writing and Running the Script
 PHP scripts are merely plain-text files containing PHP instructions, sometimes combined with
other odds and ends—JavaScript, HTML, and so on.
 So, the simplest way to write a PHP script is to pop open your favorite text editor and create a
file containing some PHP code, as follows:

<?php

Department of Computer Science Page 6


// this line of code displays a famous quotation
echo 'A horse! A horse! My kingdom for a horse!';
?>
 Save this file to a location under your Web server’s document root, and name it horse.php.
 Then, start up your Web browser, and browse to the URL corresponding to the file location.

The output of the horse.php script

UNDERSTANDING THE SCRIPT


 When you requested the script horse.php, the Apache Web server received your request,
recognized that the file was a PHP script (by means of the .php file extension), and handed it off
to the PHP parser and interpreter for further processing.
 This PHP interpreter then read the instructions between the <?php ... ?> tags, executed them,
and passed the results back to the Web server, which in turn sent them back to your browser.
 The instructions in this instance consisted of a call to PHP’s echo statement, which is responsible
for displaying output to the user; the output to be displayed is enclosed in quotation marks.
 Free-form comments can be incorporated within a PHP script via the same conventions used in
JavaScript.
 Single-line comments must be preceded by the // characters, while multiline comments must be
enclosed within a /* ... */ comment block.
 These comments are excluded from the output of the PHP script. Here are some examples:
<?php
// a single-line comment
?>
<?php
/* a multi-line
comment
block */

Department of Computer Science Page 7


?>

Handling Script Errors


 The PHP parser has a sharp eye. If your code includes an error, it will—depending on the severity of
the error—either display a warning message or stop script execution at the point of error with a
notification of what went wrong.
 To deliberately generate an error, go back to the horse.php script you created earlier and drop in an
extra semicolon after the echo keyword, so that the script now looks like this:

<?php

// this line of code displays a famous quotation

echo ; 'A horse! A horse! My kingdom for a horse!';

?>

 The PHP parser is quick to catch errors in your code.

 The error message generated by the parser is quite helpful: it tells you what the error was, as

well as the line on which it occurred.

 This makes it fairly easy—in most cases—to locate and correct the error.

The output generated by PHP when it finds a script error

Mixing PHP with HTML

 When the PHP parser reads a script, it executes only the code found between PHP tags; everything
outside these tags is ignored by the parser and returned “as is.”

 This makes it extremely easy to embed PHP code within an HTML document to create Web pages
that have all the formatting bells and whistles of standard HTML but can additionally perform
complex calculations or read and manipulate data from external sources (such as databases or Web
services).
Department of Computer Science Page 8
EXAMPLE:
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>HTML Color Table</title>
<style type="text/css">
body{
font-family: Verdana sans-serif;
}
td {
border: solid 5px white;
}
</style>
</head>
<body>
<h2>Colors with HTML and PHP</h2>
<table>
<tr>
<td>Blue</td>
<td style="width:40px; background-color:#0000ff"></td>
</tr>
<tr>
td><?php echo 'Red'; ?></td>
<td style="width:40px;
background-color:<?php echo '#ff0000'; ?>"></td>
</tr>
<?php
// this row generated through PHP
echo "<tr>\n";
echo " <td>Green</td>\n";
echo " <td style=\"width:40px; background-color:#00ff00\"></td>\n";
echo "</tr>\n";
?>
</table>

Department of Computer Science Page 9


</body>
</html>
 Save this script as colors.php, and view it in your Web browser.
 You should see an HTML page containing a table with three rows and two columns, with one
column containing a color and the other its corresponding name

 A Web page containing colors and color codes, generated by mixing PHP with HTML

ESCAPING SPECIAL CHARACTERS


 PHP allows you to escape certain characters by earlier them with a backslash (\). There so-called
escape sequences include

Sequence What It Represents


\n a line feed character
\t a tab
\r a carriage return
\" a double quotation mark
\' a single quotation mark

 When the parser encounters one of these escape sequences, it knows to replace it with the
corresponding value before sending it to the output device. Consider, for example, this line of
code:
<?php
echo "You said \"Hello\"";
?>
CHAPTER II

USING VARIABLES AND OPERATORS


STORING DATA IN VARIABLES
 A variable is simply a container that’s used to store both numeric and non-numeric information.
Department of Computer Science Page 10
Here are the most important things to know about variables in PHP.
 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 in PHP do not have basic types - a variable does not know in advance whether it
will be used to store a number or a string of characters.
 Variables used before they are assigned have default values.
 PHP does a good job of automatically converting types from one to another when
necessary.
 PHP variables are Perl-like.So, for example,

1. ASSIGNING VALUES TO VARIABLES


 Assigning a value to a variable in PHP is quite easy: use the equality (=) symbol, which also
happens to be PHP’s assignment operator.
 This assigns the value on the right side of the equation to the variable on the left.
 To use a variable in a script, simply call it by name in an expression and PHP will replace it with its
value when the script is executed.
EXAMPLE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title /></head>
<body>
<?php
// assign value to variable
$name = 'Simon';
?>
<h2>Welcome to <?php echo $name; ?>'s Blog!</h2>
</body>
</html>

 In this example, the variable $name is assigned the value 'Simon'. The echo statement is then
used to print the value of this variable to the Web page.

Department of Computer Science Page 11


 You can also assign a variable the value of another variable, or the result of a calculation. The
following example demonstrates both these situations:
EXAMPLE:
<?php
// assign value to variable
$now = 2008;
// assign variable to another variable
$currentYear = $now;
// perform calculation
$lastYear = $currentYear - 1;
// output: '2007 has ended. Welcome to 2008!'
echo "$lastYear has ended. Welcome to $currentYear!";
?>

2. DESTROYING VARIABLES
 To destroy a variable, pass the variable to PHP’s aptly named unset() function, as in the
following example:
<?php
// assign value to variable
$car = 'Porsche';
// print variable value
// output: 'Before unset(), my car is a Porsche'
echo "Before unset(), my car is a $car";
// destroy variable unset($car);
// print variable value
// this will generate an 'undefined variable' error
// output: 'After unset(), my car is a '
echo "After unset(), my car is a $car";
?>

3. INSPECTING VARIABLE CONTENTS


 PHP offers the var_dump() function, which accepts a variable and X-rays it for you.
Here’s an example:
<?php

Department of Computer Science Page 12


// define variables
$name = 'Fiona';
$age = 28;
// display variable contents var_dump($name);
var_dump($age);
?>

UNDERSTANDING PHP’S DATA TYPES


 The values assigned to a PHP variable may be of different data types, ranging from simple string
and numeric types to more complex arrays and objects.
 PHP has a total of eight data types which we use to construct our variables:
 Integers: are whole numbers, without a decimal point, like 4195.
 Doubles: are floating-point numbers, like 3.14159 or 49.1.
 Booleans: have only two possible values either true or false.
 NULL: is a special type that only has one value: NULL.
 Strings: are sequences of characters, like 'PHP 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).
1. Integers:
 They are whole numbers, without a decimal point, like 4195.
 They 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 so:
EXAMPLE:
$int_var = 12345;
$another_int = -12345 + 12345;
2. Doubles:
 They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal
places needed. For example, the code:
EXAMPLE:
$many = 2.2888800;
$many_2 = 2.2111200;
$few = $many + $many_2;

Department of Computer Science Page 13


print(.$many + $many_2 = $few<br>.);

It produces the following browser output:


2.28888 + 2.21112 = 4.5

3. Boolean:
 They have only two possible values either true or false.
 PHP provides a couple of constants especially for use as Booleans: TRUE and FALSE, which
can be used like so:
EXAMPLE:
if (TRUE)
print("This will always print<br>");
else
print("This will never print<br>");

4. NULL:
 NULL is a special type that only has one value: NULL.
 To give a variable the NULL value, simply assign it like this:

EXAMPLE:
$my_var = NULL

5. Strings:
 They are sequences of characters, like "PHP supports string operations".
 Following are valid examples of string
EXAMPLE:
$string_1 = "This is a string in double quotes";
$string_2 = "This is a somewhat longer, singly quoted string";
$string_39 = "This string has thirty-nine characters";
$string_0 = ""; // a string with zero characters

SETTING AND CHECKING VARIABLE DATA TYPES


 Unlike other programming languages, where a variable’s data type must be explicitly defined by the
programmer, PHP automatically determines a variable’s data type from the content it holds.
 And if the variable’s content changes over the duration of a script, the language will automatically
set the variable to the appropriate new data type.
Department of Computer Science Page 14
EXAMPLE:
<?php
$whoami = 'Sarah'; // define string variable

gettype($whoami); // output: 'string' echo

$whoami = 99.8; // assign new integer value to variable

gettype($whoami); // output: 'double' echo

unset($whoami); // destroy variable

echo gettype($whoami); // output: 'NULL'

?>
 This example introduces PHP’s gettype() operator, which is a handy little tool for finding out
the type of a particular variable.
 As the script output demonstrates, the variable $whoami begins life as a string, assigned the value
'Sarah'.
 It’s then assigned the number 99.8, which automatically converts it to a floating-point variable.
 Following this, the variable is de-initialized with the unset() method, which removes its value
and turns it into a NULL.
 PHP has been the invisible hand behind each of these conversions, internally resetting the data
type of $whoami from string to floating-point to null.
 Casting is a technique commonly used by Java programmers; to use it, simply specify the desired
data type in parentheses on the right side of the assignment equation.
 Consider the following example, which illustrates turning a floating-point value into an integer
value:
EXAMPLE:
<?php
$speed = 501.789; // define floating-point variable

$newSpeed = (integer) $speed; // cast to integer

$newSpeed; // output: 501


echo
?>

 In addition to the gettype() function, PHP includes a number of more specialized functions, to
test if a variable is of a specific type.

Department of Computer Science Page 15


FUNCTION PURPOSE
is_bool() Tests if a variable holds a Boolean value
is_numeric() Tests if a variable holds a numeric value
is_int() Tests if a variable holds an integer
is_float() Tests if a variable holds a floating-point
is_string() Tests
valueif a variable holds a string value
is_null() Tests if a variable holds a NULL value
is_array() Tests if a variable is an array
is_object() Tests if a variable is an object

PHP Functions to Test Variable Data Types

USING CONSTANTS
 Constants are PHP containers for values that remain constant and never change.
 They’re mostly used for data that is known well in advance and that is used, unchanged, in multiple
places within your application.
 Constants are defined using PHP’s define() function, which accepts two arguments: the name
of the constant, and its value.
 Constant names must follow the same rules as variable names, with one exception: the $ prefix is
not required for constant names.
Here’s an example of defining and using a constant in a script:
EXAMPLE:
<?php
define ('PROGRAM', 'The Matrix'); // define constants
define ('VERSION', 11.7); // use constants
// output: 'Welcome to The Matrix (version 11.7)'
echo 'Welcome to ‘ . PROGRAM . (version . VERSION . ')';
?>
MANIPULATING VARIABLES WITH OPERATORS
 Variables are simply containers for information.
 In order to do anything useful with them, you need operators.
 Operators are symbols that tell the PHP processor to perform certain actions.
 For example, the addition (+) symbol is an operator that tells PHP to add two variables or values,
while the greater-than (>) symbol is an operator that tells PHP to compare two values.
 PHP supports more than 50 such operators, ranging from operators for arithmetical operations to
operators for logical comparison and bitwise calculations.

Department of Computer Science Page 16


Per forming Arithmetic Operations

Operator Description
+ Add
- Subtract
* Multiply
/ Divide and return quotient
% Divide and return modulus
Common Arithmetic Operators
EXAMPLE:
<?php
$x = 10; // define variables
$y = 5;
$z = 3;
$sum = $x + $y; // add
echo "$x + $y = $sum\n";
$diff = $x - $y; // subtract
echo "$x - $y = $diff\n";
$product = $x * $y; // multiply
echo "$x * $y = $product\n";
$quotient = $x / $y; // divide and get quotient
echo "$x / $y = $quotient\n";
$modulus = $x % $y; // divide and get modulus
echo "$x % $y = $modulus\n";
?>

Concatenating Strings
To combine strings, use PHP’s concatenation operator, which happens to be a period (.). The
following example illustrates:
EXAMPLE:
<?php
$country = 'England'; // define variables
$city = 'London';
// combine into single string
// output: 'Welcome to London, the coolest city in all of England'
echo 'Welcome to ' . $city . ', the coolest city in all of ' .

Department of Computer Science Page 17


$country’;
?>
Comparing Variables
 PHP lets you compare one variable or value with another via its wide range of comparison
operators,
<?php
$p = 10; // define variables
$q = 11;
$r = 11.3;
$s = 11;

// test if $q is greater than $p


// returns true
echo ($q > $p);

// test if $q is less than $p


// returns false
echo ($q < $p);

// test if $q is greater than or equal to $s


// returns true
echo ($q >= $s);

// test if $r is less than or equal to $s


// returns false
echo ($r <= $s);
// test if $q is equal to $s
// returns true
echo ($q == $s);

// test if $q is equal to $r
// returns false
echo ($q == $r);
?>

Operator Description
Department of Computer Science Page 18
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
=== Equal to and of the same type
Common Comparison Operators
Per forming Logical Tests
 When building complex conditional expressions, PHP’s three most commonly used logical
operators, listed in
Operator Description

&& AND

|| OR

! NOT
EXAMPLE:
<?php
// define variables
$price = 100;
$size = 18;
// logical AND test
// returns true if both comparisons are true
// returns true here
echo ($price > 50 && $size < 25);
// logical OR test
// returns true if any of the comparisons are true
// returns false here
echo ($price > 150 || $size > 75);
// logical NOT test
// reverses the logical test
// returns false here
echo !($size > 10);
?>
Other Useful Operators
 There are a few other operators that tend to come in handy during PHP development.
 First, the addition-assignment operator, represented by the symbol +=, lets you simultaneously add

Department of Computer Science Page 19


and assign a new value to a variable

Operator Description
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign quotient
%= Divide and assign modulus
.= Concatenate and assign (strings only)

Here are examples of these in action:


<?php
// define variables
$count = 7;
$age = 60;
$greeting = 'We';
// subtract 2 and re-assign new value to variable
// equivalent to $count = $count - 2
// output: 5
$count -= 2;
echo $count;

// divide by 5 and re-assign new value to variable


// equivalent to $age = $age / 5
// output: 12
$age /= 5;
echo $age;
// add new string and re-assign new value to variable
// equivalent to $greeting = $greeting . 'lcome!'
// output: 'Welcome!'
$greeting .= 'lcome!';
echo $greeting;
?>
**************************** UNIT I COMPLETED**********************************

Department of Computer Science Page 20


QUESTION BANK-UNIT 1
2 MARKS
1. What is php?
2. What is php file?
3. What php file can do?
4. List the characteristics of php.
5. What is internet?
6. What is www?
7. What is http?
8. What is URL?
9. What is website?
10. What is web server?
11. What is web browser?
12. What is SMTP server?
13. What I s ISP?
14. What is HTML?
15. What is Hyperlink?
16. What is DNS?
17. How will you create first php file?
18. Write few points about comment lines?
19. How will you handle php script errors?
20. Write notes on escaping special character>
21. What is php variable?
22. How will you assign a variable in php?
23. How will you destroy a variable in php?
24. List the data types of php.
25. What are constants?
26. List out operators available in php.

5 MARKS AND 10 MARKS


1. Explain the characteristics of php.
2. Discuss about basic web concepts.
3. What are the basic development concepts?
4. How will you create a first php file and explain it?
5. Write a notes on storing data’s in variables.
6. Explain about php data types.
7. Write short notes on setting and checking variables in data types.
8. Explain about php operators.

Department of Computer Science Page 21

You might also like