WP Passing Package
WP Passing Package
Part - A
I – Answer any 4 questions. Each question carries 2 marks. 4x2=8
1. What is IP address?
Ans: Every machine on the internet has a unique identifying number called an IP address. The IP stands for
Internet Protocol, which is the language that computers used to communicate over the internet. Eg: IP
address looks like 216.27.61.136
Ans: A web server is a computer that stores, processes, and delivers website files to web browsers. A web
server is a computer system capable of delivering web content to end users over the Internet via a web
browser. A web server is software that runs on the web site hosting Server computer. Its main purpose is to
serve web pages; which means it waits for requests from web browsers (also known as clients) and
responds by sending the required data back.
Eg: Apache Web Server, IIS, NGINX, Oracle.
3. What is MIME?
Ans: MIME or Multipurpose Internet Mail Extensions is a specification that helps different software system
communication with each other over the internet. It does this by specifying the types of being
exchanged ,such as text, images ,audio ,video and application programmes .This is important because
different types of files required different method of interpretation and display. A MIME type is comprised as
: primary_type/subtype Ex: text/html.
Ans: PHP (Hypertext Preprocessor) is a widely-used open-source server-side scripting language designed
for web development but also used as a general-purpose programming language. It is especially suited for
creating dynamic web pages and can be embedded into HTML.
PHP scripts are enclosed within <?php and ?> tags. The structure includes the opening and closing tags,
with PHP code residing between them.
6. What is Exception Handling?
Ans: Exception handling is a programming technique used to handle errors and unexpected situations that
may occur during the execution of a program. The purpose of exception handling is to provide a way to
gracefully handle errors and prevent the program from crashing or producing incorrect results. The
exceptional situations often referred to as exceptions or errors. This can include things like division by zero,
file not found, or database connection failures. Exception handling helps ensure that program continues to
run smoothly even when unexpected issues arise.
Part - B
Ans: The JavaScript execution environment refers to the environment in which JavaScript code is executed. In web
programming, the JavaScript execution environment is typically the client's browser. The window object and
document object are two important objects in JavaScript Execution Environment.
i) The window object and the document object together provide a powerful set of tools for creating dynamic and
interactive web pages using JavaScript.
The browser provides a global object called the window object, which represents the browser window and
provides access to various properties and methods. The window object is the top-level object in the
JavaScript hierarchy and is used to interact with the browser and the user's computer.
ii) The document object is another important object in the JavaScript execution environment. It represents the web
page that is currently loaded in the browser window and provides access to the various elements on the page, such as
forms, buttons, and text boxes. The document object is a property of the window object and can be accessed using the
window.document property.
8. Write a PHP program to find Fibonacci Series
Ans:
<?php
Function fib($n){
$f1= 0; $f2= 1;
echo$f1.” ”.$f2.” ”;
for($i-2;$i<=n;$i++) {
$f3=$f1+$f2;
cho$f3.” “;
}
}
fib(10);
?>
9. Explain any 3 operators in PHP
Ans: PHP Arithmetic Operators: The arithmetic operators are used to perform common
arithmetical operations, such as addition, subtraction, multiplication etc. Here's a
complete list of PHP's arithmetic operators:
Operator Description Example Result
+ Addition $x + $y Sum of $x and $y
PHP Assignment Operators: The assignment operators are used to assign values to variables.
Operator Description Example Is The Same As
= Assign $x = $y $x = $y
+= Add and assign $x += $y $x = $x + $y
PHP Comparison Operators: The comparison operators are used to compare two values in a Boolean
fashion.
Operator Name Example Result
Less than or
<= equal to $x <= $y True if $x is less than or equal to $y
Ans: ARRAYS
Array is used to store multiple values of same type in single variable. An array is a special variable, which
can hold more than one value at a time.
CREATE AN ARRAY IN PHP
In PHP, the array() function is used to create an array.
Syntax:$var= array( );
TYPES OF ARRAY IN PHP
There are three types of array in PHP, which are given below.
echo$student[3][0].":".$student[3][2].".<br>";
Marks: ".$student[3][1].", Class:
?>
Output: Harry: Marks: 300 Class: 11
Varsha: Marks: 400 Class: 10
Gaurav: Marks: 200 Class: 8
Hitesh: Marks: 220 Class: 8
Ans: COOKIES: A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you
can both create and retrieve cookie values.
OR
PHP cookie is a small piece of information which is stored at client browser. It is used to recognize the user.
OR
Cookies are text files stored on the client computer and they are kept of use tracking purpose
Create Cookies With PHP A cookie is created with the setcookie() function.
Syntax ssetcookie ( string name [, string value [, int expire [, string path [, string domain [, bool
secure]]]]] )
Parameter Description
name The name to set the cookie variable to and hence
the name to access it with
value The value of the current cookie
expire When a cookie will expire (in the form of a Unix
timestamp)
path The directory where the cookie will be available for
use
domain The domain at which the cookie will be available
1.Using forms and elements array of document object: This is the original way (DOM 0) to access the elements using
forms and elements array of document object.
Syntax: document.forms[number].elements[number]
Example: <script type=”text/javascript”>
function function1(){
var Name = document.forms[0].elements[0].value;
var Age = document.forms[0].elements[1].value;
var Phone = document.forms[0].elements[2].value;
}
</script>
2.Using form names: It’s better to use the names of the forms and elements. In XHTML, we have to give a name to
each form and each element.
var name_element=document.getElementById(“NameText”);
var age_element=document.getElementById(“AgeText”);
var phone_element=document.getElementById(“PhoneText”);
var submit_element=document.getElementById(“myButton1”);
14. What is XML? Explain XML Namespaces.
Ans: The eXtensible Markup Language is a text document used mainly for distributing the data on internet between
different applications. It9s a structured document for storing and transporting the data, mainly used for the
interchanging the data on internet.
In XML, a namespace is used to prevent any conflicts with element names. Because XML allows to create our own
element names, there’s always the possibility of naming an element exactly the same as one in another XML
document, this is possible when they never use both documents together.
We can create a name conflict by creating a namespace for the XML document. To use XML namespace, elements
are given qualified names. These qualified names consists of two parts:
1.The local part is the same as the names we have been given elements.
Example:
<?xml version=”1.0”encoding=”UTF-8”?>
<!DOCTYPE books SYSTEM “bookrules dtd”>
<bk:books xmlns:bk=”http://www.musite.com”>
<bk:book type=”programming”>
<bk:title>Web programming</bk:title>
<bk:author>Srikanth.S</bk:author>
</bk:book>
</bk:books>
15. Explain DTD and Types of DTD
Ans: 1.What is DTD? Explain internal DTD and external DTD. A DTD is a Document Type Definition. A DTD
defines the structure and the legal elements and attributes of an XML document.
1.Internal DTD: An internal DTD is the DTD is defined between the square brackets within the XML documents.
RULES:
1. The document type declaration must be written in between the XML declaration and the root element.
2. Keyword DOCTYPE must be followed by the root element.
3. Keyword DOCTYPE must be in upper case.
Example:
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tom</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
2.External DTD: An external DTD is nothing different from internal DTD except that defining DTD in an external
file. It can be use with more than one XML document.
Example:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tom</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
14. Explain DOM tree Traversal and Modification.
Ans:
DOM Tree Modification refers to the process of adding, modifying, or deleting elements and content from the DOM
tree structure of a document. This is an important aspect of web development, as it allows developers to dynamically
update the content of a web page in response to user actions or other events.
15. Explain Positioning of Elements in JavaScript
Syntax
selector { position: value; }
Here, selector' is the HTML element to which the 'position' property is being applied, and
'value' is one of the four possible values: 'static', 'relative', 'absolute', or 'fixed'. The 'position'
property is used to specify the type of positioning method used for an HTML element.
Types of Positioning
The position property indicates that an element is to be positioned, and specifies which positioning
method should be used.
1 Static Positioning:
• This is the default value. Elements are positioned according to the normal flow of the document.
• The top, right, bottom, and left properties have no effect on statically positioned elements.
• A statically positioned element is placed in the document flow as it would normally appear.
• Normal paragraphs and divs are static by default and stack as they appear in the HTML
2 Relative Positioning:
• An element with position: relative; is first laid out just like a static element.
• A relatively positioned element is positioned relative to its normal position in the document flow
It can then be shifted from its normal position using top, right, bottom, and left properties.
• Other content will not adjust to fill the space left by the element when it moves.
• The distinctive behaviour of relative positioning is that the space the element would have
occupied in the normal flow is preserved.
• For example, If we want to move a button slightly to the right from where it would normally be,
we could use position: relative; left: 20px;
3 Absolute Positioning:
• The absolute position in CSS is a powerful property that allows for precise placement of an
element within a webpage, independent of the normal flow of document content.
• When an element is given position: absolute;, it is taken out of the normal document flow.
• This means it no longer affects the positioning of other elements in the document. These other
elements behave as if the absolutely positioned element doesn't exist.
• The final position of an absolutely positioned element is relative to its closest ancestor element
that has a position other than static. If no such ancestor exists, it defaults to positioning relative to
the <html> element (essentially, the entire page).
4 Fixed Positioning:
• The top, right, bottom, and left properties are used to position the element.
• Fixed elements are removed from the document flow and positioned relative to the browser
window rather than another element in the document.
• Example: A "back to top" button can be made with position: fixed; bottom: 20px; right: 20px; so it
hovers at the bottom right of the screen, even when scrolling.
Ans: An XML Schema describes the structure of an XML document. The XML Schema language is also referred to
as XML Schema Definition (XSD). The purpose of an XML Schema is to define the legal building blocks of an XML
document.
• Data types that are already defined in XML schema specification and ready to use in schema to declare
elements and attributes are known as built-in data types. XML Schema provides many built-in data types.
*primitive data:
1 Boolean 2. String 3.Decimal 4. Float
*Built in derived data:
1.Token 3.language 4.Name 5.Entity
*Data derived from decimal primitive data:
1.Integer 2.Non positive integer 3.Negetive integer 4.Int
Example: In the below code, we have used xs:string for FirstName and LastName, xs:integer for Age,
xs:date for DOB, and xs:float for Percentage. They are not explicitly defined as simple type elements.
Instead, the type is defined with the type attribute. Because the value (string, integer,date, and float) is a
simple type, the elements themselves are simple-type elements.
•A complex-type element can be empty, contain simple content such as a string, or can contain complex
content such as a sequence of elements. It is not necessary to explicitly declare that a simple-type element
is a simple type, but it is necessary to specify that a complex-type element is a complex type.
• Content Models: Content models are used to indicate the structure and order in which child elements can
appear within their parent element. Content models are made up of model groups.
Ans: A loop is a way of executing lines of code repeatedly. If we want to print "Hello" on the screen 100
times then we can either use echo statement 100 times or we can put one echo statement in a loop that runs
100 times which takes very minimum number of lines of code.
Executing set of statements repeatedly is called iteration or loop. The iterative statements are also
called as looping statements or repetitive statements. In programming specifically, iterative
statements are referred to as sequence of statements or code repeatedly executed until a specific
condition is true. The main looping constructs in PHP are:
1. while loop
2. do...while loop
3. for loop
4. foreach loop
While Statement
The while loop in PHP is used to repeatedly execute a block of code as long as a specified
condition is true. It tests the condition before executing the loop body. It's used for iterative
tasks where the number of iterations isn't known beforehand. It's written just like an if
statement, except that it uses the while keyword.
Eg:
<?php
$ch=’a’;
while($ch<=’’) {
echo $ch;
$ch++;
}
?>
Do-while Statement
The do-while loop in PHP is a control structure that executes a block of code at least once
before checking a condition at the end of the loop. It differs from the while loop in that it
guarantees the execution of the loop body at least once, regardless of the condition. This means
that the loop body always executes at least once, even if the expression is always false.
Example: <?php
$count=1; do {
echo "Count is: 11 . $count . "<br>";
$count++;
}
while ($count <=5) ;
?>
For Loop Statement
A for loop is a repetition control structure that allows to efficiently write a loop that needs to be
executed a specific number of times. A for loop is useful when we know how many times a
task is to be repeated. The for statement contains the initialization expression, test expression
and update expression in one line thereby providing a shorter, easy to debug structure of
looping.
Example: <?php
for ($i = 1; $i <= 5; $i++) {
echo "Number” . $i . "<br>";
}
?>
Foreach Loop Statement
The foreach loop in PHP is a control structure specifically designed for iterating over arrays
and objects. It provides a simple way to traverse through each element in an array or each
property of an object without the need for counters or more complex syntax. It is particularly
useful when we need to process each element of an array or object without knowing the size or
structure of the data in advance.
Example: <?php
$numbers = [1, 2,3, 4, 5];
foreach ($numbers as $number)
{
echo $number "<br>";
}
?>
Model Paper -2
Part - A
I – Answer any 4 questions. Each question carries 2 marks. 4x2=8
Ans: A web browser is a software application used to locate and display web pages. It is able to retrieve,
find, view, and send information over the internet.
Ans: Uniform Resource Locator or URL is a fancy name for address. It contains information about where a
file is and what a browser should do while it. Each file on the Internet has a unique URL.
Ans:
mousedown
mouseup
mouseover
mousemove
mouseouy
click
4. What is DNS?
Ans: Domain Name System is a database system that translates a computers fully qualified domain name
into an IP address. The DNS is used to resolve human readable hostnames into machine readable IP address.
DNS also provides other information about domain names such as mail services.
5. . Define DHTML?
Ans: DHTML stands for Dynamic Hyper Text Markup Language. DHTML is not a language or a web
standard. DHTML is a term used to describe the technologies used to make web pages dynamic and
interactive.
Ans: A for loop is a repetition control structure that allows to efficiently write a loop that needs to be
executed a specific number of times. A for loop is useful when we know how many times a task is to be
repeated. The for statement contains the initialization expression, test expression and update expression in
one line thereby providing a shorter, easy to debug structure of looping
Part - B
Ans:
The World Wide Web often referred to as the "WWW" or simply the "Web" is a system of interconnected
documents and other resources linked by hyperlinks and URLS (Uniform Resource Locators) that are
accessed over the Internet. Sir Tim Berners-Lee, a British computer scientist, invented the World Wide Web
The World Wide Web is a service that runs on the Internet. It's a collection of documents and resources that
are accessed over the Internet. The other services that run on the Internet apart from the Web include email,
In simple terms, WWW or the Web is a collection of websites or web pages stored in web servers and
accessed using web browsers through the internet. The websites contain text pages, digital images, audios,
videos, etc. Users can access the content of these sites from any part of the world over the internet using
Ans:
Echo Print
It is a language construct . It is a function like a construct.
It does not require parentheses . It requires parentheses.
It does not have return value. It allows returns the value 1.
It is faster than print . It is slightly slower than echo
It can output multiple values separated by comma. It can only out put a single expression.
It can be used as a part of more complex It cannot be used as a part of more complex
expression. expression.
Syntax: echo value1,value2,…..value_n; Syntax: print(value)
Ans:
12. Define a Cookie? Explain the process of creating a cookie with an example.
Part - C
III – Answer any 4 questions. Each question carries 8 marks. 4 x 8 = 32
Ans: The DOM 2 event model is a standard for handling events in web browsers. It is an improvement over
the original DOM event model, which had some limitations and inconsistencies. The DOM 2 event model
defines a standard set of event types and provides a way to register event listeners for those events. It also
introduces the concept of event propagation, which allows events to be handled at different levels of the
document hierarchy. The DOM 2 event model is supported by most modern web browsers and is widely
used in web development.
While the DOM 0 model is still widely supported and used, the DOM 2 model introduces a more modular
and flexible way to manage events, with better support for a wider range of event types and interactions.
1. Standard Event Types: The DOM 2 event model defines a standard set of event types, such as click,
mouseover, and keydown. This makes it easier for developers to write cross-browser code that works
consistently across different platforms.
2. Event Listeners: The DOM 2 event model provides a way to register event listeners for specific events.
This allows developers to write code that responds to user actions, such as clicking a button or typing in a
text field.
3. Event Propagation: The DOM 2 event model introduces the concept of event propagation, which allows
events to be handled at different levels of the document hierarchy. This means that an event can be handled
by an element's parent, grandparent, or even higher up in the document tree.
4. Event Object: The DOM 2 event model provides an event object that contains information about the
event, such as the target element, the type of event, and any data associated with the event.
There are two types of event propagation: bubbling and capturing.
1. Capturing: When an event occurs on an element, it is first handled by the top-level element (ie, the
document object), and then it "captures" the event as it propagates down the DOM hierarchy to the
element that triggered the event. Capturing is less common than bubbling and is not supported by all
browsers.
Example: Let's say that the document contains a <div> which contains a <p> which contains an
<img>. Further, let's say we have added an event listener to all of them. When a user clicks on the
image, a mouseclick event occurs. Even though the user clicked the image, the image doesn't get the
event first. Instead, the event listener attached to the document grabs the event first and processes it.
(That is, it captures the event before it gets to its intended target <img>.) The event is then passed
down to the <div>'s event listener. The event then goes to the <p>, and finally to the <img>. That is,
all of the clicked-on object's "ancestors" higher up in the document capture the event for processing
before sending it down the chain to its intended target.
2. Bubbling: Bubbling is the most common type of event propagation. When an event occurs on an
element, it is first handled by that element, and then it "bubbles up" to its parent element, and then to
its parent's parent, and so on, until it reaches the top of the DOM hierarchy (i.e., the document
object).
Example: We have an <img> inside a <p>, which is inside a <div>, which is inside the document.
When a user clicks the image, this time the events rise like a bubble in a glass of water. The click's
original target, the <img>, gets to see the event first and it processes, and then passes it upwards to
the <p> for further processing, which passes it on to the <div>, which finally passes it up to the
document for processing.
Ans:
1. Using "on" Attribute in HTML: This app he first approach for registering event handlers in
HTML is to use the "one attributed this approach is simple and straightforward, where we can specify
the name of the event and the name of the function that will be called when the event occurs.
However, this approach has some limitations, especially for larger projects, as it can be difficult to
manage and debug code that uses this approach.
Example:
<html>
<head>
<title>Event Handling Example</title>
<style>
#message {
font-size: 20px;
margin-top: 20px;}
</style>
</head>
<body>
<h1>Event Handling Using "on" Attributes</h1>
<button onclick="changeText()">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
function changeText() {
document.getElementById("message").innerText = "You clicked the button!";
alert("Button was clicked!"); }
</script>
</body>
</html>
In this example, "changeText()" is the name of the function that will be executed when the button is
clicked.
2. Using DOM Event Handlers: The second approach is to use the "addEventListener" method in
JavaScript. This approach is more flexible and powerful than using the "on" attribute in HTML. It
allows to register multiple event handlers for the same event, remove event handlers, and more.
Example: <html >
<head>
<title>Event Handling with DOM Event Handlers</title>
<style>
#message {
font-size: 20px;
margin-top: 20px; }
</style>
</head>
<body>
<h1>Event Handling Using DOM Event Handlers</h1>
<button id="myButton">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
const button = document.getElementById("myButton");
const message = document.getElementById("message");
function changeText() {
message.innerText = "You clicked the button!";
alert("Button was clicked!"); }
button.addEventListener("click", changeText);
</script>
</body>
</html>
In this example, "myButton" is the ID of the button element, and "changeText" is the name of the function
that will be executed when the button is clicked
3. Using Event Handler Properties: This method involves assigning a function to the event handler
property of an HTML element. The event handler could also be registered by the assignment to the
associated event property on the button object as shown below, For example, to add a click event
handler to a button element, you can use the following code:
Example: <html >
<head>
<title>Event Handling with Event Handler Properties</title>
<style>
#message {
font-size: 20px;
margin-top: 20px; }
</style>
</head>
<body>
<h1>Event Handling Using Event Handler Properties</h1>
<button id="myButton">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
const button = document.getElementById("myButton");
const message = document.getElementById("message");
button.onclick = function() {
message.innerText = "You clicked the button!";
alert("Button was clicked!"); };
</script>
</body>
</html>
In this example, "myButton" is the ID of the button element, and "function" is the name of the
function that will be executed when the button is clicked.
• Compound If Statements: You may also compound the statements using elseif to have multiple
conditions tested in sequence. You should use this construction if you want to select one of many sets
of lines to execute.
<?php
$num1 = 12;
$num2 = 15; $num3=20; if ( ( $num1 <$num2) && ($num2<$num3) )
{ echo “$num1 is 12, $num2 is 15 and $num3 is 20"; } ?>
• PHP if-else statement is executed whether condition is true or false. If-else statement is slightly
different from if statement. It executes one block of code if the specified condition is true and another
block of code if the condition is false. The syntax if-else statement is:
if (condition)
{ statements_1 } else
{ statements_2 }
• PHP if...elseif...else Statement is a special statement used to combine multiple if?.else statements. So, we
can check multiple conditions using this statement.The if...elseif...else statement executes different codes
for more than two conditions. The syntax:
if (condition1) {
//code to be executed if condition1 is true
} elseif (condition2) {
//code to be executed if condition2 is true
} elseif (condition3) {
//code to be executed if condition3 is true
....
} else {
//code to be executed if all given conditions are false
}
• The Nested if contains the if block inside another if block. Here, the inner if statement executes only
when specified condition in outer if statement is true. The syntax for the Nested if is:
if (condition) {
//code to be executed if condition is true if (condition) {
//code to be executed if condition is true }
else{
//code to be executed if condition is false
}}
• Switch statements work the same as if statements. However, the difference is that they can check for
multiple values. Of course you do the same with multiple if..else statements, but this is not always the
best approach. A switch statement allows a program to evaluate an expression and attempt to match
the expression’s value to a case label. If a match is found, the program executes the associated
statement. One can use the switch statement to select one of many blocks of code to be executed.
Syntax:
Switch (expression)
{
Case label1: code to be executed if expression = label1; break;
Case label2: code to be executed if expression = label2; break;
default: Code to be executed if expression is different from both label1
and label2; }
16. Explain Looping statements in PHP
2. catch Block:
This block is used to handle the exception that was thrown in the 'try' block. It contains code that is
executed when an exception is caught. The 'catch' block specifies the type of exception that it can
handle and if the caught exception matches the specified type, the code in the 'catch" block is executed.
We can catch specific types of exceptions by specifying the exception type in the parentheses after
catch.
SECTION-C
13. What are the different ways of accessing elements in Javascript. Explain with an example.
14. Explain the properties and methods used for DOM tree traversal and modification.
Short Answer
1. DOM
Ans: Refer MQP 1 Q 10
2. HTML VS XML.
Ans:
Ans: Dynamic Content in web development refers to the ability to change the content of
HTML on a web page dynamically using JavaScript. This can involve updating text, images,
or other content in response to user interactions, data changes, or other events without
requiring reload. The concept of dynamic content is important as it allows web developers to
create more user and Responsive user interfaces. By updating content dynamically, web
pages can provide real feedback, display live data, and adapt to user input, resulting in a more
engaging and personalize user experience.
4. Data type supported in PHP
Ans: PHP is a dynamically-typed language, which means that the data type of a variable is
determined at runtime based on the value assigned to it. For example, if we assign a string to
a variable, and later assign an integer, PHP will handle the conversion automatically.
Example: $name = "Srikanth"; // This is a string variable
$name 40; // This is an integer variable
PHP variables are loosely typed, which means that they can hold different types of data, and
their type can change during the execution of a program. For example, a variable that Initially
holds a string value can later be assigned a numeric value.
5.Namepace
6.URL
8. Define Internet.
Ans: The Internet is also known as the INTERconnected NETwork is a wide area network
(WAN) that connects millions of computing devices (also called hosts or end-systems) across
the world. It emerged as a promising technology for providing widespread access to millions
of private, public, academic, business, and government networks. It is linked by an extensive
range of electronic, wireless, and optical networking technologies. The Internet enables
communication between different types of networks and devices.
9.echo() vs print()
10.Operator precedence.
Ans:
<?php
Output: 12
<?php
?>
Example
<?php
$str=strtolower($str);
echo$str; ?>
Example
<?php
$str="Hello friends i AM Hitesh";
$str=strtoupper($str);
echo
$str; ?>
Output: HELLO FRIENDS I AM HITESH
Syntax: rtrim(string,charlist)
<?php
$str = "Hello World!"; echo $str . "<br>";
echo rtrim($str,"World!");
?>
Output: Hello World!
Hello
Ans:
Break:
The PHP break keyword is used to terminate the execution of a loop prematurely. The
break statement is placed inside the statement block. It gives you full control and
whenever you want to exit from the loop you can come out. After coming out of a
loop immediate statement to the loop will be executed.
Example: In the following example condition test becomes true when the counter value
reaches 3 and loop terminates.
<?php
$i-0;
while( $i < 10) {
$i++;
if( $i == 3 )
break;}
echo ("Loop stopped at i = $i" ); ?>
Continue:
The PHP continue keyword is used to halt the current iteration of a loop but it does not
terminate the loop. Just like the break statement the continue statement is placed inside
the statement block containing he code that the loop executes, preceded by a
conditional test. For the pass encountering continue statement, rest of the loop code is
skipped and next pass starts.
Example: In the following example loop prints the value of array but for which
condition becomes true it just skip the code and next value is printed.
<?php
$array = array( 1, 2, 3, 4, 5);
foreach( $array as $value ){
if( $value == 3 ) continue;
echo "Value is $value <br/>";}?>
Output: Value is 1 Value is 2 Value is 4 Value is 5