0% found this document useful (0 votes)
6 views5 pages

PHP Server-Side Scripting Basics

The document provides an overview of PHP, a popular server-side scripting language used for creating dynamic web pages. It covers various aspects of PHP including variable declaration, data types, loops, and functions, as well as comparisons between PHP and JavaScript. Additionally, it explains different types of arrays, operators, and the three-tier architecture of PHP.

Uploaded by

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

PHP Server-Side Scripting Basics

The document provides an overview of PHP, a popular server-side scripting language used for creating dynamic web pages. It covers various aspects of PHP including variable declaration, data types, loops, and functions, as well as comparisons between PHP and JavaScript. Additionally, it explains different types of arrays, operators, and the three-tier architecture of PHP.

Uploaded by

gopugfbgfbgfb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10 .

Server side Scripting using PHP


1. Write short note on PHP
PHP is one of the most popular server side scripting languages and it is an open-source
project and is completely free. It is used for creating dynamic web pages. PHP stands for
PHP Hypertext Preprocessor. PHP script produces hypertext (HTML) as a result after its
execution. PHP scripting should begin with <?php and end with ?>. The PHP code
containing text documents are saved with .php extension.
2. What is the use of var_dump( ) function in PHP?

var_dump( ) function used to display both data type and value of variables. It can be used to display
integer, float, string, array, objects etc.

3. Explain variable declaration in PHP with example

In PHP, a variable is declared by using the $ sign followed by the variable name.
Data type of the variable is decided when value is assigned to it

Eg. $a = 10;

4. What are the naming rules of variable in PHP?

Rules for forming PHP variable names:

1. Variable name must start with the $ sign.


2. The name must begin with a letter or an underscore.
3. Can contain alphanumeric characters and underscores (a-z, A-Z, 0-9, _).
4. Variable names are case-sensitive ($name and $NAME are different).
5. Punctuation characters like commas, quotation marks, or spaces are not allowed

5. What is the use of foreach loop in PHP?


foreach loop is an extension of for loop in C++. foreach loop is used with an array of
unknown number of elements. foreach loop works only with array and it has two formats
a). foreach($array as $vaue) loop
b). foreach($array as $key => $value ) loop
1. In PHP , arrays that use string keys are called …………
Associative array

2. List the core data types in PHP


Integer, float, Boolean, String

3. Write PHP code to display even numbers below 100


<?php

$
i=2
;do
{
echo ” $i ” ;
$i = $i + 2 ;
} while ( $i <= 100 ) ;
?>

4. Name the global variables used for passing data using HTTP GET and POST request.
$_GET,$_POST

5. What is the difference between echo and print in PHP?


In PHP echo and print are used to display output on webpage
6. a) Compare Indexed and associative arrays in PHP.
b) Write a PHP program to display the prime numbers below 50.
a) Arrays with numeric index are called indexed arrays. They are almost similar to arrays
in C++. They use nonnegative integers as keys. The function array ( ) can be used to create an
array.
Syntax: $array_name = array ( value1, value2, value3,…. ) ;
Arrays with named keys are called associative arrays. Associative arrays have their index as
string.
Syntax: $array_name = array ( key=>value , key=>value, key=>value ,…. ) ;

7. Compare echo() and print()

echo print
Can take more than one parameters can used Can take only one parameter
without parenthesis
Does not return any value Returns true on successful output and false if
it is unable to print the string
Little faster than print( ) Little bit slower than echo( )

8. PHP is ……
a. freeware b. proprietary c. both d. none
Ans. a. freeware
9. In PHP, the name of a variable starts with -----------sign

10. Prepare a short note about different data types used in PHP

Core Data Types:

1. Integer:
o Whole numbers without a fractional part.
o Can be positive, negative, or zero.
o Example: $x = 10;
2. Float/Double:
o Numbers with decimal points or in exponential form.
o Example: $y = 10.5; or $z = 1.2e3;
3. String:
o A sequence of characters enclosed in single or double quotes.
o Example: $str = "Hello World";
4. Boolean:
o Represents two possible states: TRUE or FALSE.
o Example: $isTrue = true;

Special Data Types:

1. Null:
o Represents a variable with no value.
o Example: $var = null;
2. Array:
o
A collection of values stored in a single variable.
o
Can be indexed (numeric keys) or associative (string keys).
o
Example: $arr = array("Apple", "Banana", "Cherry");
3. Object:
o Represents an instance of a class.
o Example:
4. Resource:
o Special variables that hold references to external resources like database
connections or file handles.
o Example: $file = fopen("[Link]", "r");
11. What is the difference between PHP and JavaScript?
PHP is server side scripting language

JavaScript is client side scripting language

12. What are the difference between GET and POST methods in form submitting ?

GET POST
Information is passed as part of the URL Information is embedded within the body of
HTTP request
Visible to everyone Invisible to others
Fast but not secure Secure but slow
Can only send 2000 characters No limit

13. A web server that supports PHP on any operating system is


Apache

14. The PHP operator used to join two strings is .


The . (dot) operator

15. Write any two string functions in PHP and their uses.

strlen() Returns the length of a string. strlen(“hello”) returns 5


strpos() Finds the position of the strpos (“hello”, “e”)
first occurrence of
returns 1
a string inside another string.

strcmp() Compares two strings strcmp (“he”, “HE”)


returns False

16. Describe three tier architecture of PHP.


Tier 1. The frond end in which the content is rendered by the browser
Tier 2. A middle dynamic content processing and generation level containing a web or
application server.
Tier 3. A back end database or data store

17. Briefly explain about operators in PHP.


Arithmetic operators + – * / %
Increment, decrement ++ – –
Assignment operator =
Relational operators < <= > >= == !=
Logical operators || or && and ! xor
String concatenation .
Combined operators += –= *= /= % = .=

18. Explain the three types of arrays used in PHP. Give example for each type.
Arrays
There are three types of arrays: i) Indexed arrays, ii) Associative arrays and
iii) Multidimensional arrays
Indexed arrays: Arrays with numeric index are called indexed arrays. They are almost
similar to arrays in C++. By default array index (or subscript) starts from zero.
The function array( ) can be used to create an array.

$array_name = array(value1,value2,value3,etc.);
Eg: $marks = array(54, 45, 56, 60, 40);
echo $days[3];
Associative arrays: Arrays with named keys are called associative arrays. Associative
arrays have their index (or subscript) as string.
$array_name = array(key=>value, key=>value, key=>value, etc.);
Eg: $marks = array(“Hari”=>54, “Ravi”=>45, “Mini”=>56);
echo $marks[“hari”]; gives 54 as output.

You might also like