PHP Assignment

You might also like

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

PHP ASSIGNMENT

QUESTION BANK
1 ST UNIT

DONE BY :
20-ucs-029
20-ucs-032
20-ucs-033
20-ucs-042
20-ucs-044
20-ucs-046
2 Marks :
1.Benefits of PHP :
• PHP is a platform Independent general purpose Scripting language.
• Since it is platform Independent, it supports all as like windows, Unix,
Linux.
• PHP has built in modules which helps to connect to database easily.

2. Benefits of MySQL :
• MySQL is considered easy to use
• MySQL is a highly scalable product
• MySQL’s maturity also lends itself to security

3. Benefits of Javascript :
• Javascript is a open source programming language which means it has
a huge community support
• JavaScript allows third party integration
• The most significant benefit using this language is on the client-side

4. Benefits of CSS :
• CSS saves time in which we can write CSS once and then reuse the
same sheet in multiple HTML pages
• CSS is easy to maintain
• CSS changes are device friendly

5. Write about Apace Web Server :


• Apache is a free and open-source web server that delivers web content
through the internet
• Apache is developed and maintained by an open community of
developed under the auspices of Apache software foundation
• Apache has its ability to handle large amounts of traffic with minimal
configuration

6. Write about HTML :


HTML stands for Hyper Text Markup Language. It is used for web page
development. HTML is written using HTML elements which consists of tags,
primarily and opening and closing tag.
7. What is HTTP :
HTTP stands for Hyper Text Transfer Protocol . It is a great means for the
world wide web. HTTP is the protocol to exchange or transfer Hyper Text.

8.Combining PHP with HTML :


<html>
<head>
<title>Combining PHP</title<>
</head>
<body bgcolor=”white”>
<P>A Paragraph of Text</P>
<?PHP
Echo”Hello”;
?>
</body>
</html>

9.Write about the features of PHP:


* Speed
* Full database support
* Cross Platform
* Easy for new comer and advance features.

10. Write any 5 basics of PHP :


* Constraints
* Variables
* Datatype
* Operators and operands
* Arrays

11. What is dynamic page content in php ?


Dynamic content is personalized and adapts based on the data you have
about the user on the access time. Its goal being to deliver an engasins and
satisfies online experience for the viewers.
12. What is constraints in php ?
Constraints are used to limit the type of data that can go into a table.
This ensures the accuracy and reliability of the data in the table.

13. What is variable ?

A variable can have a short name (like x and y) or a more descriptive name.
Rules for PHP variables:A variable starts with the $ sign and it can start with a
letter or the underscore character.

14. What is datatype ?

A datatype in programming is a classification that specifies which type of


value a variable has and what type of mathematical operations can be applied
to it without causing an error.
15. Array :

An array is a special variable that we use to store or hold more than one
value in a single variable without having to create more variable to store those
values.

16.Type of arrays :

* Assossiative array

* Indexed array

* Linear array

17. What is a php ?

• php is a server side scripting language.

• php means pre processor hypertext scripting language.

18. Write any two functions of php.

Php supports many databases like MYSql and Postgre Sql etc.

19. What is a php file ?

Php file can contain text, HTML, CSS, JavaScript and php code.

Php files have extension “.php”.

20. What can php do ?

• Php can generate dynamic page control.

• Php can collect form data.


• Php can be used to control user access.

21. Write the important features of php.

• Php runs on various platforms (windows, linux)

• Php is compitabe with almost all server

• Php is easy to learn and runs effectively on the server side.

22. What is a parser in php ?

Php parser is a library that takes a source code which in php, parses it
through a logical analyzer, and creates its respective syntax tree.

23. What are the different ways to parse php code ?

Php parser, Php Sundbox, Php Mess Detector, Php checkstyle, Php
analyzer.

24. The main features provided by this php parser.

• parsing php 7 and php8 code into an abstract syntax tree.

• Invalid code can be parsed into a partial AST.

• The AST contains accurate location informations.

25. What is XML parser function ?

XML parser is a software library or a package that provides interface for


client applications to work with XML documents.
26. What is the use of php parser ?

Parsers are used when there is a need to represent input data from
source code abstractly as a data structure so that it can be checked for the
current syntax.

27. Write the structure of php.

<?php

echo “hello and hi”;

?>

Output :

Hello and Hi

28. Basic structure of php.

The server executes the php scripts, which will send the html output to
the browser. Normally HTML and php tags can be present. A popular open
source general programming language, php or hypertext pre processor may be
built into an html.

29. What are the advantages of php?

• Improved loading speed.

• Cheaper hosting services.

• Good flexibility.

• Wide selection of databses.


30. What is open source in php ?

Open source is code that is designed to be publicly accessibley anyone


can see, modufy and distribute the code as they see fit.

31. What are the control flow in php ?

• Conditional Statement

• Loop statement

• Jump Statement

32. What are conditional statements in php ?

• if statement

• if else statement

• if elseif else statement

• Nested if statement and switch statement

33. What are the loop statements in php ?

• For loop

• while loop

• do while loop

• for each loop

34. what are jump statement in php ?

• Go to
• Continue

• break and return statement.

35. write a program using if else statement.

<?php

$a=2;

$b=3;

if($a<$b)

{ echo “ a is smaller”; }

Else

{ echo “ b is smaller”; }

?>

36. What is looping statement in php ?

Loops are used to execute the same block of code again and again as
long as a certain condition is true.

37. Write syntax for foreach loop.

for each(array as value)

Code to be executed

}
38. Write static and dynamic linking.

Static linking :

Required code and data is copied into executable at compile time.

Dynamic linking :

Required code and date is linked to executable at real time.

39. What is Dynamic context in php ?


Dynamic context is personalized and adopts based on the data type you
have about the user and on the access time.

40. What is conditional looping statement in php?

If statement executes some code if one condition is true if else


statement executes some code if a condition is true and another code if that
condition is false.

10 MARK :

1. Give introduction to Php :

* Php is called as preprocessor hypertext language.

* It was developed by Rasmos Lerdorf in 1995.

* It was previouslly called as personal language.

* It is a general purpose server side scripting language.

* It is free open source.

* It is easy to learn and run efficiently on the server side.

* It supports wide range of databases (oracle, Mysql etc).


* It supports various platforms (Linux, Microsoft).

* Php can encrypt data.

* Php can send and receive cookies.

* Php can generate dynamic page control.

* Php can be used to control user access.

2. Define features and working of Php :

Features :

* Speed

* Full database support

* Open source and free to download and use.

* Cross platform.

* Easy for new comer and advance features.

* Used to create dynamic web pages.

* Freedom to choose any opertaing system and a web server.

* Not constrained to output only HTML. Php's abilities including outputiing


images, PDF files etc.

* Support for a wide range of database. Eg: dbase, Mysql, Oracle etc.

* Support for talking to other services using protocols such as IMAP, POP3,
HTTP.

* Php includes free and open source libraries with the case build.

Working :
* Url is typed in the browser.

* The browser send a request to the web server.

* The web server then calls the Php script on that page.

* The php module executes the script, which then sends out the result in the
form of HTML back to the browser, which can be seen on the screen.

3. What is Php parser ?

Php parser is a library that takes a source code which in php, parses it
through a logical analyzer, and creates its respective syntax tree.

In php there are two types of XML parsers :

* Tree - Based parsers

* Event - Based parsers

Tree - Based parsers :

Tree based parsers holds the entire documents in memory and


transforms the XML document into a Tree structure.

It analyzes the whole document, and provides access to the Tree elements
(DOM).

This type of parser is a better option for smaller XML documents, but not for
large XML document as it causes major performance issues.

Example of Tree - Based parsers:

* Simple XML

* DOM

Event - Based parsers :


Event - based parsers do not hold the entire document in memory,
instead, they read in one mode at a time and allow you to interact with in real
time. Once you move onto the next mode, the old once is thrown away.

This type of parser is well suited for large XML documents. Its parsers faster
and consumes less memory.

Example of event - based parsers :

* XML reader

* XML Expert parser

4. Define structure of php.

<html>

<body>

<?php

echo"hi freinds....";

?>

</body>

</html>

A php script can be placed anywhere in the document. A php script starts
with <?php and

ends with ?> .

The default file extension for php files is ".php". A php file normally contains
HTML tags,

and some php scripting code. This means that php code is embedded in HTML
code.
5. Explain if and if else statements with example.

Very often when we write code, we want to perform different actions


for different decisions

we can use conditional statements in our code to do this. In php we have the
following conditional statements.

i) if statement :

We use this statement to create some code only if a specified condition is


true. When the condition gets satisfied, then the code written in if block is
executed.

Syntax :

if(condition)

code to be executed

Example:

<?php

$a=10;

if($a==10)

echo"Correct";

?>

Output :
Correct

In this example the variable a is declared 10 and the if condition gets satisfied
so the statement

inside the if block is executed.

ii) if else :

When we need to display one code when the condition is true and
another code when the condition is false, then if else statement is used.

Syntax:

if(condition)

code in true block

else {

code to be executed when the condition is false

Example :

<?php

$a=10;

if($a==5)

echo"Entered";

}
else {

echo"Error value";

?>

Output :

Error value

In the above example the condition is false (variable a is not 10), so the else
block is executed.

6. Explain if elseif else and switch statement

i) if elseif else:

When a selected code need to be executed among many codes then this
statement is used.

Syntax :

if(condition)

code to be executed

elseif(condition){

code to be executed

else{
code to be executed

Example :

<?php

$a=10;

if($a==100){

echo "Okay";

else if($a==10){

echo "perfect";

else{

echo "Error";

?>

Output :

perfect

In the above example the condition satisfies the elseif block, so the code in
the elseif

block executed.

ii) switch :
When a selected code used to be executed among many codes, then this
statement is used.

Syntax :

switch($n){

case 1:

code for case 1

case 2:

code for case 2

default:

code for default value

Example :

<?php

$a=10;

switch($a)

case 3:

echo "3";

case 10:

echo "10";

default:

echo "Error";

?>
Output :

10

Here case 10 gets satisfied, therefore it is executed. Default value is used to


compiler

from continuing.

7. Explain for and for each statements with example.

i) for:

To execute the code for the specified number of conditions.

Syntax :

for( init; condition; increment)

code to be executed

The init is the initial value, condition is the one which needs to be executed,
and the increment value is used to set the values by which need to be
incremented.

Example :

<?php

for($a=1;$a<6;a++)

echo "$a";

}
?>

Output :

12345

In the above example, the variable a is assigned 1, condition is less than


6, increment

values is 1, so values 1 to 5 is displayed.

ii) foreach :

This statement is used to access the elements in the array. The variable
should

assign to $ value.

Syntax :

foreach($a as $ value)

code to be executed

Example :

<?php

$a=array("car","bike");

foreach($a as $ value)

echo "$ value.</br>";

}
?>

Output :

car

bike

In the above example $a is assigned with array constitutes values car and
bike. Then $a

is assigned to $ value. Then the values are displayed using echo function.

8. Explain while and do while with example.

i) while :

It is used to run the loop based on the condition. The condition is


checked

first and then it is executed.

Syntax :

while(condition)

code to be executed;

increment value;

Example :

<?php

$a=1;

while($a<3)
{

echo "$a";

$a=$a+1;

Output :

12

In the above example a is assigned 1. Variable condition is less than 3.


Increment value is 1. Hence 1 and 2 is displayed.

ii) do while:

Here the code is executed once. Then the condition is checked and the
loop runs

based on the condition.

Syntax :

do{

code to be executed;

increment value;

while(condition)

Example :

<?php

$a=10;

do{

echo "$a";
$a++;

while($a<5)

?>

Output :

10

In the above example value is 10. The value once displayed. Then the
condition

is checked and it is false hence the loop stops.

9. Write about dynamic linking in php.

PHP is a programming language, and the output from it can be completely


different for each user, it’s possible for an entire website to run from a single
PHP web page.

it’s much more sensible to split your website development into different parts.
For example, one distinct process is signing up for a website, along with all the
checking this entails to validate an email address, check whether a username is
already taken, and so on.

Dynamic Linking in Action

One of the more popular PHP-driven applications on the Web today is the
blogging platform WordPress or a blog reader, you might not realize it, but
every major section has been given its own main PHP file, and a whole raft of
generic, shared functions have been placed in separate files that are included
by the main PHP pages as necessary.

<?php

// Connect to the databaase

$PDO = new PDO("mysql:host=*;dbname=*", "*", "*");


// set the PDO error mode to exception

$PDO->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);

// Set up defaults

$current_title = "";

$current_page_data = "";

// Check if the user posted the page

if($_SERVER['REQUEST_METHOD'] == 'POST') {

// Check if user pressed a menu button

if(isset($_POST["menu"])) {

// User has selected a menu, meaning a page was selected, now


load the page

$current_title = filter_input(INPUT_POST, "menu");

// Now get current data from the database, if the page was never
created, add it to the database

$stmt = $PDO->prepare("SELECT * FROM pages WHERE


pageheader=?");

$stmt->execute([$current_title]);

$row = $stmt->fetch();

if($row) {

// Page is in the databaswe already, load the text for it

if(isset($row["pagetext"]) AND trim($row["pagetext"])!="") {


$current_page_data = $row["pagetext"];

} else {

// Page was never created, add it with blank text

$current_page_data = "This page is under


contruction!<br><br>Please check back again later!";

?>

The above code is the example for dynamic linking in php.

10.Breifly explain : a) HTTP b)HTML

a)HTTP :

• HTTP stands for Hyper Text Transfer Protocol

• It is a great means for the world wide web

• HTTP is the protocol to exchange or transfer Hyper Text

• Hyper Text is a multi-linear set of objects that are used to build a network by
using hyperlinks

between the nodes, such as text or words.


• It is an application layer protocol in the Internet protocol suits exceded for
distributed,

collaborative, hypermedia information systems.

Purpose of HTTP:

HTTP is method for encoding and transporting information between a


client(such as

a web browser) and a web browser. Also it is the primary protocol for
transmission of

information across the internet.

b)HTML :

• HTML stands for Hyper Text Markup Language

• It is used for web page development

• HTML is written using HTML elements which consists of tags, primarily and
opening and

closing tag

• The data between these tags is usually the content

• HTML 5 is the current revision of HTML which is considered to be one of the


best compared

to previous HTML versions

• It is a system which is used to mark text for World Wide Web page in order
to obtain

colours, style, pictures etc.

Purpose of HTML :

HTML is the code that is used to structure a web page and its content.
11. List out the benefits of PHP and MySql.

i) Benefits of PHP :

• PHP is a platform Independent general purpose Scripting language.

• Since it is platform Independent, it supports all as like windows, Unix, Linux.

• Multiple platform support in PHP saves a lot of effort and expenses.

• PHP is open source, Hence it has great community support.

• Since PHP it has been for open source 21 years, Most bugs are discovered
and resolved by

developers which makes PHP very stable.

• It can work efficiently with different databases, such as Apache, MySQL and
PostgreSQL.

•The cost of building a website using PHP is small.

• PHP has built in modules which helps to connect to database easily.

• PHP can be integrated without effort with other technologies such as java
which saves time

and money.

ii) Benefits of MySql :

• MySQL is considered easy to use

• MySQL is a highly scalable product


• MySQL’s maturity also lends itself to security

• Since it is regularly updated and has a vibrant developer community, MySQL


become a stable

and secure choice among RDBMS

• MySQL is reliable -not just from a data perspective, but from a development
perspective

• MySQL has regular patches, releases and an entrenched developer


community that works

with it

• This makes MySQL a safe choice compared to newer, less mature RDBMS
options

• MySQL does lock functionality behind paid versions of RDBMS

• MySQL is a open source RDBMS.

12. Elaborate the benefits of JAVA and CSS.

i) Benefits of JAVASCRIPT :

• Javascript is a open source programming language which means it has a huge


community

support

• The most significant benefit using this language is on the client-side

• By using it on the client-side, it would be able to add up a good interaction


between the users

and web page


• Since javascript is supported by all web browser, the projects can be directly
run through the

browser

• Javascript has massive support of powerful frameworks, with the help of it


you can create

high-end projects seamlessly in a short period of time

• JavaScript allows third party integration

• The essential benefit of Javascript is that you would be able to create highly
efficient

multifunctional websites

ii) Benefits of CSS :

• CSS saves time in which we can write CSS once and then reuse the same
sheet in multiple

HTML pages

• CSS is easy to maintain

• Cascading Sheet not only simplifies website development, but also simplifies
the maintenance

as change of a line of code affects the whole website and maintenance

• Easy for the user to customize the online page

• It has the power of re-positioning which helps us to determine the changes


within the

position of web elements

• CSS changes are device friendly

• It is less complex therefore the efforts are significantly reduced


• It helps us to achieve a responsive website

13. Define Apache Web server, discuss in detail.

• Apache is a free and open-source web server that delivers web content
through the internet

• Apache is developed and maintained by an open community of developed


under the auspices

of Apache software foundation

• The vast majority of Apache server instances run on Linux distribution

• Being open-source has made Apache very popular with developers who have
built and

configured their own modules to apply specific functionality

• Apache has been around since 1995 and is responsible as a core technology
that helped the

initial growth of the internet in its infacy

• Apache has its ability to handle large amounts of traffic with minimal
configuration

• The latest version of Apache is version 2.4

Features and facts :

• Apache can process dynamic contexts within the webserver itself without
having to rely on any

external components.

• It is used by 43.2% websites all over the world.


• The Apache Agent discreas Apache modules as backwards.

• The name 'Apache' was chosen from respect for the various Native American
nations

collectively referred to an Apache.

• The Apache HTTP server allows loading modules with extensive support for

software and application integration.

You might also like