Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CHAPTER 4 INTRODUCTION TO PHP

Namma Kalvi
< ?php
www.nammakalvi.org $num = 1;
$num1 = 2;
PART II
print $num . “+”. $num1 ;
?>
Choose the Correct Answers
a) 3 b) 1+2
c) 1.+.2 d) Error
1. What does PHP stand for?
a) Personal Home Page 8. Which of the following PHP statements will
b) Hypertext Preprocessor output Hello World on the screen?
c) Pretext Hypertext Processor a) echo (“Hello World”); b) print (“Hello World”);
d) Pre-processor Home Page c) printf (“Hello World”); d) sprintf (“Hello World”);

2. What does PHP files have a default file 9. Which statement will output $x on the
­extension? screen?
a) .html b) .xml a) echo “\$x”; b) echo “$$x”;
c) .php d) .ph c) echo “/$x”; d) echo “$x;

3. A PHP script should start with ___and end 10. Which of the below symbols is a newline
with ___: character?
a) <php> b) < ? php ?> a) \r b) \n
c) < ? ? > d) < ?php ? > c) /n d) /r

4. Which of the following must be installed on ANSWERS FOR OBJECTIVES


your computer so as to run PHP script?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
a) Adobe b) windows
b c b c e d c a b a
c) Apache d) IIS

5. We can use ___ to comment a single line? PART III


i) /? ii) // iii) # iv) /* */
a) Only (ii) Short Answers
b) (i), (iii) and (iv)
c) (ii), (iii) and (iv)
1. What are the common usages of PHP?
d) Both (ii) and (iv)
™™ PHP can be used on all major operating systems.
e) Both (ii) and (iii)
™™ PHP has also support for most of the web servers
6. Which of the following PHP statement/ today. This includes Apache, IIS, and many others.
statements will store 41 in variable num? ™™ The main advantage of creating your own PHP
(i) $x = 41; (ii) $x = ‘41’; (iii) (i) $x = “41”; GUI(Graphical User Interface)
a) Both (i) and (ii) b) All of the mentioned. ™™ PHP can interact with MySQL databases
c) Only (iii) d) Only (i) ™™ PHP can perform all types of calculations and It
can collect user information.
7. What will be the output of the following PHP
code?

SURYA 1
Chapter - 4  Introduction to PHP www.nammakalvi.org XII Std - Computer Application
2. What is Web server? Example:
™™ A Web server is Software that uses HTTP ™™ If you defined variable in lowercase, then you
(Hypertext Transfer Protocol) to serve the files need to use it in lowercase everywhere in
that form Web pages to users program.
™™ Web server software that runs on server
8. How to declare variables in PHP?
hardware, governs the server side scripting
­
™™ Variable name must always begin with a $
­compilation into an intermediate byte-code that
symbol.
is then interpreted by the runtime engine.
™™ Variable name can never start with a number.
3. What are the types scripting language? ™™ Variable names are case-sensitive.
Web scripting languages are classified into two
9. Define Client Server Architecture.
types,
™™ Client-server architecture is a network architec-
™™ Client side scripting language
ture in which each computer or process on the
™™ Server side scripting language
network is either a client or a server.
4. Difference between Client and Server? ™™ Servers are powerful computers or processes
Client Server dedicated to managing disk drives printers, or
The client-side The server-side network traffic
­environment used to ­environment that runs a ™™ Clients are PCs or workstations on which users
run scripts is usually a scripting language is a run applications.
browser. web server. 10. Define Web server.
Does not need server Requires server   A Web server is Software that uses HTTP (Hyper-
Interaction interaction. text Transfer Protocol) to serve the files that form
Example: HTML, CSS, Example PHP, ASP.net, Web pages to users.
JavaScript etc. Ruby on Rails, Python,
etc.
PART IIII
5. Give few examples of Web Browser?
™™ Google Chrome Explain in Brief Answer
™™ Mozilla Firefox
™™ Opera 1. Write the features of server side scripting
™™ Safari language.
™™ Internet Explorer ™™ Server-side scripting offers greater protection for
™™ UC Browser user privacy
™™ Netscape Navigator etc. ™™ It often reduces the loading time for web pages
™™ Some browsers don’t fully support JavaScript, so
6. What is URL?
server-side scripting is essential to run dynamic
™™ URL is the abbreviation of Uniform Resource
pages on these browsers.
Locator
™™ It is the address of a specific Web page or file on 2. Write is the purpose of Web servers?
the Internet. ™™ A web server (or Web server) is server software,
™™ URL is made up four parts–protocols, hostname, or hardware dedicated to running said software,
folder name and file name. that can satisfy World Wide Web client requests.
™™ Example: http://www.google.com/ ™™ A web server can, in general, contain one or
more websites.
7. Is PHP a case sensitive language?
™™ A web server processes incoming network
Yes, PHP is a case sensitive language
requests over HTTP and several other related
­
protocols.

2 SURYA
XII Std - Computer Application Chapter - 4  Introduction to PHP
3. Differentiate Server side and Client Side Scripting language.
Basis for
Server-side scripting Client-side scripting
comparison
Works in the back end which could not be visible at Works at the front end and script are
Basic
the client end. visible among the users.
Does not need interaction with the
Processing Requires server interaction.
server.
L a n g u a g e s PHP, ASP.net, Ruby on Rails, ColdFusion, Python, et-
HTML, CSS, JavaScript, etc.
involved cetera.
Could effectively customize the web pages and provide
Affect Can reduce the load to the server.
dynamic websites.
Security Relatively secure. Insecure

4. In how many ways you can embed PHP ™™ The processing takes place on the end users
code in an HTML page? computer.
™™ There are two ways to use HTML on your PHP ™™ The source code is transferred from the web
page. server to the user’s computer over the internet
™™ The first way is to put the HTML outside of your and run directly in the browser.
PHP tags. You can even put it in the middle if you ™™ The scripting language needs to be enabled
close and reopen the tags. on the client computer. Sometimes if a user is
™™ The second way to use HTML with PHP is by conscious of security risks they may switch the
­using PRINT or ECHO. By using this method you scripting facility off.
can include the HTML inside of the PHP tags. ™™ When this is the case a message usually pops up
to alert the user when script is attempting to run.
5. Write short notes on PHP operator.
™™ Operator is a symbol which is used to perform
Server-side Environment
mathematical and logical operations in the
™™ A server is a computer system that serves as a
­programming languages.
central repository of data and programs and is
™™ Different types of operator in PHP are:
shared by clients
•• Arithmetic operators
™™ The server-side environment that runs a ­scripting
•• Assignment operators
language is a web server.
•• Comparison operators
™™ A user’s request is fulfilled by running a script
•• Increment/Decrement operators
directly on the web server to generate dynamic
•• Logical operators and
HTML pages.
•• String operators
™™ This HTML is then sent to the client browser.
™™ It is usually used to provide interactive web sites
PART IVI
that interface to databases or other data stores
on the server.
Explain in detail
™™ This is different from client-side scripting where
1. Explain client side and server side scripting scripts are run by the viewing web browser,
language. ­usually in JavaScript.
  Web scripting languages are classified into two ™™ The primary advantage to server-side scripting
types, client side and server side scripting language. is the ability to highly customize the response
based on the user’s requirements, access rights,
Client-side Environment or queries into data stores.
™™ The client-side environment used to run scripts is
usually a browser.

SURYA 3
Chapter - 4  Introduction to PHP www.nammakalvi.org XII Std - Computer Application
2. Discuss in detail about Website develop- Step 2:
ment activities. •• After downloading. MSI file from Apache
™™ Web development concept describes in detail foundation Website, user launches the. MSI
about Website development and hosting through file and clicks next and next button to finish
network (Internet/Intranet). the installation on server machine.
™™ The process of development also includes •• The software takes default port number 130
•• Web content generation or 130130.
•• Web page designing •• Once the user finished, the Web server
•• Website security and so on. ­software is installed and configured on server
hardware machine as a service.
Website Development Life Cycle
1. Information Gathering Step 3:
•• Set goals for the website •• To test the installation of Apache Httpd
•• Define website’s target audience Webserver, enter the following URL from your
2. Planning Web browser which is installed in your client
•• Create a sitemap sketch machine.
•• Create a wireframe/mockup https://localhost:130/ or https://­
•• Select technology stack localhost:130130
3. Design •• The output page that says “Its works”
•• Create colorful page layouts Step 4:
•• Review the layouts •• Administrator user can start, stop and ­restart
•• Get client’s feedback on the layouts the Web server service at any time via
•• Change the layout when required ­windows Control panel.
4. Content writing and assembly •• Once the services stops, the client machine
•• Create new content will not receive the response message from
•• Get content ready for migration server machine.
5. Coding Step 5:
•• Build and deploy website •• Webserver’s configuration setting file “httpd.
•• Add special features and website conf ” is located in the conf directory under
•• Testing, Review and Launch the apache installation directory.
6. Test the create website •• Edit this file and enable the PHP module to
•• Upload the website to server run PHP scripting language.
•• Final test and launch
4. Discuss in detail about PHP data types.
7. Maintenance and Regular updating
™™ PHP scripting language supports 13 primitive
•• Add report system
data types.
•• Fix bugs
™™ Data Types plays important role in all program-
•• Keep website up-to-day
ming languages to classify the data according to
3. Explain the process of Webserver the logics.
­installation. ™™ PHP supports the following data types.
  The following are the steps to install and config- •• String
ure Apache Httpd Web server and PHP module in •• Integer
windows server machine. •• Float
•• Boolean
Step 1: •• Array
•• Go to Apache foundation Website and •• Object
­download the Httpd Web server Software. •• NULL
https://httpd.apache.org/download.cgi •• Resource

4 SURYA
XII Std - Computer Application Chapter - 4  Introduction to PHP

Data type Explanation Example


String is a collection of characters within
String $x = “Computer Application!”;
the double or single quotes
Integer is a data type which contains non decimal
Integer $x = 59135;
numbers.
Float Float is a data type which contains decimal numbers. $x = 19.15;
Boolean is a data type which denotes the $x = true;
Boolean
possible two states, TRUE or FALSE $y = false;
Array is a data type which has multiple values in single $cars = array(“Computer”,”Laptop”,”­
Array
variable. Mobile”);
It is a data type which contains information about data
Object $school_obj = new School ();
and function inside the class.
Null is a special data type which contains
NULL $x = null;
a single value: NULL
Resource is a specific variable, it has $handle = fopen(“note.txt”, “r”);
Resources
a reference to an external resource. var_dump($handle);

5. Explain operators in PHP with example.


™™ Operator is a symbol which is used to perform mathematical and logical operations in the programming
languages.
™™ Different types of operator in PHP are:
•• Arithmetic operators,
•• Assignment operators,
•• Comparison operators,
•• Increment/Decrement operators,
•• Logical operators, and
•• String operators.

Arithmetic operators
™™ The arithmetic operators in PHP perform ­general arithmetical operations, such as addition, ­subtraction,
­multiplication and division etc

Symbol Operator Name Purpose


+ Addition This operator performs the process of adding numbers
- Subtraction This operator performs the process of subtracting numbers
* Multiplication This operator performs the process of multiplying numbers
/ Division This operator performs the process of dividing numbers
% Modulus This operator performs the process of finding remainder in division
­operation of two numbers

Assignment Operators:
™™ Assignment operators are performed with numeric values to store a value to a variable.
™™ The default assignment operator is “=”. This operator sets the left side operant value of expression to right
side variable.

SURYA 5
Chapter - 4  Introduction to PHP www.nammakalvi.org XII Std - Computer Application

Assignment Similar to Description


x=y x=y This operator sets the left side operant value of expression to right
side variable
x += y x = x+ y Addition
x- = y x=x-y Subtraction
x* = y x = x*y Multiplication
x/ = y x = x/y Division
x%=y x=x%y Modulus

Comparison Operators:
™™ Comparison operators perform an action to compare two values.
™™ These values may contain integer or string data types (Number or Strings).

Symbol Operator Name Symbol Operator Name


== Equal > Greater than
=== Identical < less than
!= Not equal >= Greater than or equal to
<> Not equal <= Less than or equal to
!== Not identical

Increment and Decrement Operators:


™™ Increment and decrement operators are used to perform the task of increasing or decreasing variable’s value.
™™ This operator is mostly used during iterations in the program logics.
Operator Name Description
++$x Pre-increment Increment $x value by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one

Logical Operators:
™™ Logical Operators are used to combine conditional statements.

Symbol Operator Name Example Result


&& And $x && $y True if both $x and $y are true
║ Or $x ║ $y True if either $x or $y is true
! Not !$x True if $x is not true
xor Xor $x xor $y True if either $x or $y is true, but not both

String Operators:
™™ Two operators are used to perform string related operations such as Concatenation and Concatenation
­assignment (Appends).
Operator Name Example Result
. Concatenation $text1 . $ text2 Concatenation of $txt1 and $txt2
.= Concatenation $text1 .= $ text2 Appends $txt2 to $txt1

6 SURYA
XII Std - Computer Application Chapter - 4  Introduction to PHP
11. Which of the following is an assignment
ADDITIONAL QUESTIONS AND ANSWERS: ­operator?
a) = b) = = c) = = = d) ! = =
PART AI
12. Which of the following is an identical
Choose the correct answers: ­operator?
a) = b) = = c) = = = d) ! = =
1. The variable in PHP begins with a dollar 13. Which of the following is an non-identical
______symbol operator?
a) @ b) # c)$ d) %
a) = b) = = c) = = = d) ! = =
2. The assignment activity implemented 14. Which of the following is an equal ­operator?
­using ___ operator, a) = b) = = c) = = = d) ! = =
a) + b) - c) * d) =
15. PHP, ____is released by theofficial team on
3. In PHP, Variable name can never start with 30 November 2017.
a_____. a) 7.1 b) 7.2
a) alphabet b) number
c) 7.3 d) All of the above
c) both a and b d) either a or b
16. ______is a collection of characters within
4. PHP scripting language supports _____ the double or single quotes
primitive data types. a) String b) Boolean
a) 10 b)1 1 c) 12 d) 13
c) Integer d) Float
5. PHP was invented by _______ 17. Boolean is a data type which denotes___
a) RasmusLerdorf b) Dennis Ritchie
a) Integer numbers b) Decimal point numbers
c) Bjarne Strousrup d) James Goasling
c) True or False state d) Array
6. PHP was invented in _____ 18. ____ is a data type which has multiple
a) 1992 b) 1993
­values in single variable.
c) 1994 d) 1995
a) Integer numbers
7. PHP can embed with _____ b) Decimal point numbers
a) HTML b) CSS c) True or False state
c) Javascript d) All of the above d) Array

8. Which of the following isthe important 19. We can use ___ to comment multiple lines?
server side Web and general purpose a) /? b) // c) # d) /* */
scripting language? 20. ____is a data type which contains
a) HTML b) CSS
­information about data and function inside
c) Javascript d) PHP
the class.
9. PHP also creates ______ Webpages in a) Integer numbers b) Array
­thereal time Web development projects. c) True or False state d) Array
a) Dynamic b) interactive
c) both a and b d) None of these ANSWERS FOR OBJECTIVES
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
10. 78.9 % of Website are developed by_____
c d b d a c d d c d
scripting language.
a) ASP b) JSP 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.
c) VbScript d) PHP a c d b c a c d d d

SURYA 7
Chapter - 4  Introduction to PHP www.nammakalvi.org XII Std - Computer Application

Abbreviations: PART CI
ASP - Active Server Page Explain in Brief Answer
JSP - Java Server page.
CSS - CascadingStyle Sheets
1. Write the Characteristics of PHP.
PHP - Hypertext Pre-processor
WWW - World Wide Web ™™ Open Source
CGI - Common GatewayInterface ™™ Case Sensitive
OOPs - Object Oriented Programming ™™ Simplicity Program language
™™ Efficiency Program language
PART BI ™™ Platform Independent Program language
™™ Security Program language
Short Answers
™™ Flexibility Program language

1. What is the purpose of Var_dump() ™™ Real-Time Access Monitoring Program language


­function? 2. Write short note on Var_dump() function
™™ The var_dump() function is used to dump with Example.
­information about a variable. ™™ The var_dump() function is used to dump
™™ This function displays structured information ­information about a variable.
such as type and value of the given variable. ™™ This function displays structured information
2. Classification of Client Server Architecture such as type and value of the given variable.
Model. ™™ Arrays and objects are explored recursively with
  Client server architecture is classified into three values indented to show structure.
types, as follows
™™ Single Tier Architecture Example:
<?php
™™ Two Tier Architecture
$x = “COMPUTER APPLICATION!”;
™™ N/Multi/Three tire architecture. $x = null;
3. Write the types of PHP Syntax. var_dump($x);
™™ Three types of PHP Syntax are available. ?>
™™ They are as follows OUTPUT: NULL

•• Default Syntax 3. What do you mean by Resources?


•• Short open Tags ™™ Resource is a specific variable.
•• HTML Script embed Tags ™™ It hasa reference to an external resource.

4. What is the main advantage of PHP ­variable ™™ These variables hold specific handlers tohandle
declaration? files and database connections irrespective PHP
 The main advantage of the PHPvariable program.
declaration is, it does not requires tospecify the
­
data type keyword separately such as int, char,
float, double or string etc.

8 SURYA
XII Std - Computer Application Chapter - 4  Introduction to PHP

PART DI

Explain in detail

1. Explain all the types of syntax in PHP.

Default Syntax:
™™ The default Syntax begins with “<?php”and c­ loses with “?>”.

Short open Tags


™™ The Short open Tags begins with “<?” andcloses with “?>”.
™™ But admin user has toenable Short style tags s­ ettings in php.ini fileon the server.

HTML Script embed Tags:


™™ HTML Script embed Tags looks just likeHTML scripts tags.

www.nammakalvi.org
SURYA 9

You might also like