0% found this document useful (0 votes)
121 views12 pages

HTML Tags, URL Structure, DHTML, PHP

Here are the key points about foreach loop in PHP: - The foreach loop iterates over arrays and objects, providing an easy way to loop through all the elements/properties. - It assigns the value of the current element into the $value variable on each iteration. Optionally, it can also assign the key to the $key variable. - The syntax is: foreach (array_expression as $value) or foreach (array_expression as $key => $value) - On each iteration, the array pointer is automatically advanced to the next element. - It is commonly used for looping through the values of an array, accessing each one and performing some operation with it. - It saves writing code

Uploaded by

Gurpreet Singh
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)
121 views12 pages

HTML Tags, URL Structure, DHTML, PHP

Here are the key points about foreach loop in PHP: - The foreach loop iterates over arrays and objects, providing an easy way to loop through all the elements/properties. - It assigns the value of the current element into the $value variable on each iteration. Optionally, it can also assign the key to the $key variable. - The syntax is: foreach (array_expression as $value) or foreach (array_expression as $key => $value) - On each iteration, the array pointer is automatically advanced to the next element. - It is commonly used for looping through the values of an array, accessing each one and performing some operation with it. - It saves writing code

Uploaded by

Gurpreet Singh
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
You are on page 1/ 12

Assignment PGD-2102

Web Technologies

USOL-PGDCA

GURPREET SINGH BEDI


ROLL NO-56463
PGDCA- 2nd SEMESTER (2019-2020)
Q1: What are HTML tags?

Ans: ​An HTML tag is commonly defined as a set of characters constituting a formatted
command for a Web page. At the core of HTML, tags provide the directions or recipes for the
visual content that one sees on the Web.
HTML tags have always been important in the history of Web design. During the early days of
the World Wide Web, they were responsible for a majority of Web code. That may not be the
case anymore, but HTML tags are still at the center of how Web pages are formatted. Other
kinds of languages have been built around the backbone of HTML, such as Cascading Style
Sheets (CSS), which makes it easier to create consistent and overarching styles and color
schemes.
HTML tags include tags for references, tags for tables, tags for headlines or titles, etc. An HTML
tag consists of the tag name in angular brackets and may come in pair, which makes up the
beginning and ending tag that frame a particular piece of code, text or other tags. The
beginning tag consists of the name, optionally followed by one or more attributes, whereas the
ending tag consists of the same name preceded by a forward slash ("/"). For example, the HTML
tag "<p>" begins a paragraph, whereas "</p>" ends that paragraph. This is a consistent syntax
in HTML.

Q2: What is the basic structure of an URL?

Ans: URL (or URL-address) is a special form of individual address of a certain resource on the
Internet. It can refer to the website, some particular document, or an image. The Internet user
just needs to insert this code into the location bar to find the needed website, document,
folder, or image. In plain language, it means the following: due to the URL address, the user
gets information about where the needed information is located.URL is an abbreviation which
stands for the term Uniform Resource Locator. It contains a link to the server which is a storage
of the searched resource. In general, URL meaning is the track from the server to the final
gadget (which is a platform of the user’s work) can be illustrated rather simply. The upper
element is the resource server, the lowest one – the user’s device. All the points in between the
two are additional servers. A URL is also a specific type of Uniform Resource Identifier (URI).

URL address has a determined structure which includes:

● method of access to the resource that is also named the network protocol;
● access authorization;
● hosts – DNS address that is inscribed as IP address;
● port – one more obligatory detail included in combination with IP address;
● track – determines the information about the method of gaining access;
● parameter – the internal information of resource about the file.

GURPREET SINGH BEDI ROLL NO-56463


Q3: What are the benefits of using DHTML over normal HTML?

Ans:

1. In comparison to other multimedia software like Flash and shockwave, it took less
space. Those resulted in short download time which saved bandwidth as well as made
website quick.
2. DHTML was fast & zippy depending upon your device and ISP. You didn’t need an extra
plugin to make it work efficiently as it used the features present in the browsers. The
content loaded on the fly. The whole page didn’t load promptly and saved time for end
users by altering just the content part.
3. It was supported in some form or shape by major browsers from Microsoft, Netscape. It
also worked well with cell phones, PDAs, and PDFs.
4. DHTML was considered to design friendly offering web designers different options to
give web pages a compact look. It had more advanced functionality than a static HTML
& holds more content on the web page at the same time.
5. What made DHTML famous at its prime was its outlook. It was popular among clients
due to its sleek nature & flexibility to make changes to their data.
6. Due to low file maintenance, it saves time for web designers and is more efficient for
content management. The use of dynamic XML made the high volume of content look
reasonable avoiding any lag.

GURPREET SINGH BEDI ROLL NO-56463


Q4: What is PHP? Describe features of PHP.

Ans: PHP started out as a small open source project that evolved as more and more people
found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in
1994.
● PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
● PHP is a server side scripting language that is embedded in HTML. It is used to manage
dynamic content, databases, session tracking, even build entire e-commerce sites.
● It is integrated with a number of popular databases, including MySQL, PostgreSQL,
Oracle, Sybase, Informix, and Microsoft SQL Server.
● PHP is pleasingly zippy in its execution, especially when compiled as an Apache module
on the Unix side. The MySQL server, once started, executes even very complex queries
with huge result sets in record-setting time.
● PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4
added support for Java and distributed object architectures (COM and CORBA), making
n-tier development a possibility for the first time.
● PHP is forgiving: PHP language tries to be as forgiving as possible.
● PHP Syntax is C-Like.
Common uses of PHP
● PHP performs system functions, i.e. from files on a system it can create, open, read,
write, and close them.
● PHP can handle forms, i.e. gather data from files, save data to a file, through email you
can send data, return data to the user.
● You add, delete, modify elements within your database through PHP.
● Access cookies variables and set cookies.
● Using PHP, you can restrict users to access some pages of your website.
● It can encrypt data.
The main features of php is; it is open source scripting language so you can free download this
and use. PHP is a server site scripting language. It is open source scripting language. It is widely
used all over the world. It is faster than other scripting language. Some important features of
php are given below

Features of PHP

It is most popular and frequently used world wide scripting language, the main reason of
popularity is; It is open source and very simple.

GURPREET SINGH BEDI ROLL NO-56463


● Simple
● Faster
● Interpreted
● Open Source
● Case Sensitive
● Simplicity
● Efficiency
● Platform Independent
● Security
● Flexibility
● Familiarity
● Error Reporting
● Loosely Typed Language
● Real-Time Access Monitoring

Simple

It is very simple and easy to use, compare to other scripting language it is very simple and
easy, this is widely used all over the world.

Interpreted

It is an interpreted language, i.e. there is no need for compilation.

Faster

It is faster than other scripting language e.g. asp and jsp.

Open Source

Open source means you no need to pay for use php, you can free download and use.

Platform Independent

PHP code will be run on every platform, Linux, Unix, Mac OS X, Windows.

Case Sensitive

GURPREET SINGH BEDI ROLL NO-56463


PHP is case sensitive scripting language at time of variable declaration. In PHP, all keywords
(e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT
case-sensitive.

Error Reporting

PHP have some predefined error reporting constants to generate a warning or error notice.

Real-Time Access Monitoring

PHP provides access logging by creating the summary of recent accesses for the user.

Loosely Typed Language

PHP supports variable usage without declaring its data type. It will be taken at the time of
the execution based on the type of data it has on its value.

Q5: Write a program in PHP to find greatest of three numbers.

Ans:
<?php
$a=20;
$b=10;
$c=1;
if($a>$b && $a>$c)
{
echo "Greater value is a=".$a;
}
else if($b>$a && $b>$c)
{
echo "Greater value is b=".$b;
}
else if($c>$a && $c>$b)
{

GURPREET SINGH BEDI ROLL NO-56463


echo "Greater value is c=".$c;
}
else
{
echo"Dont Enter Equal Values";
}
?>

Q6: Explain the purpose and use of foreach loop in PHP.

Ans: The ​foreach loop​ is mainly used for looping through the values of an array. It loops over
the array, and each value for the current array element is assigned to $value, and the array
pointer is advanced by one to go the next element in the array. The foreach construct provides
an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an
error when you try to use it on a variable with a different data type or an uninitialized variable.
There are two syntaxes:

foreach (array_expression as $value)

statement

foreach (array_expression as $key => $value)

statement

The first form loops over the array given by array_expression. On each iteration, the value of
the current element is assigned to $value and the internal array pointer is advanced by one (so
on the next iteration, you'll be looking at the next element).The second form will additionally
assign the current element's key to the $key variable on each iteration.It is possible to
customize object iteration.

Syntax:
<?php
foreach (array as $value){
//code to be executed;
}

GURPREET SINGH BEDI ROLL NO-56463


?>
Example:
<?php
$salary[]=2000;
$salary[]=3000;
$salary[]=5000;
foreach($salary as $value){
echo "Salary: $value<br>";
}
?>
Output:
Salary: 2000
Salary: 3000
Salary: 5000

Q7: Write a program in PHP to find a factorial of a number using recursion.

Ans:
<?php
function factorial($number) {
if ($number < 2) {
return 1;
} else {
return ($number * factorial($number-1));
}
}
echo factorial(4);
?>

GURPREET SINGH BEDI ROLL NO-56463


Q8: Write a program in PHP to reverse a string.

Ans:
<?php
$string = "WEBTECHNOLOGES";
$length = strlen($string);
for ($i=($length-1) ; $i >= 0 ; $i--)
{
echo $string[$i];
}
?>

Q9: What is Index array? Explain with examples in PHP.

Ans: PHP indexed array is an array which is represented by an index number by default. All
elements of array are represented by an index number which starts from 0.
PHP indexed array can store numbers, strings or any object. PHP indexed array is also known as
numeric array.
There are two ways to define indexed array:
1st way:
$size=array("Big","Medium","Short");
2nd way:
$size[0]="Big";
$size[1]="Medium";
$size[2]="Short";
Example:
<?php
$size=array("Big","Medium","Short");
echo "Size: $size[0], $size[1] and $size[2]";

GURPREET SINGH BEDI ROLL NO-56463


?>
Output:
Size: Big, Medium and Short
File: array2.php
<?php
$size[0]="Big";
$size[1]="Medium";
$size[2]="Short";
echo "Size: $size[0], $size[1] and $size[2]";
?>
Output:
Size: Big, Medium and Short

Q10: What is a file? Explain various file handling functions available in PHP?

Ans:​ A file is simply a resource for storing information on a computer.


Files are usually used to store information such as;
● Configuration settings of a program
● Simple data such as contact names against the phone numbers.
● Images, Pictures, Photos, etc.
File handling is needed for any application. For some tasks to be done file needs to be
processed. File handling in PHP is similar as file handling is done by using any programming
language like C. PHP has many functions to work with normal files. Those functions are:
1) ​fopen() – PHP fopen() function is used to open a file. First parameter of fopen() contains
name of the file which is to be opened and second parameter tells about mode in which file
needs to be opened, e.g.,
<?php
$file = fopen(“demo.txt”,'w');
?>
Files can be opened in any of the following modes :

GURPREET SINGH BEDI ROLL NO-56463


“​w​” – Opens a file for write only. If file not exist then new file is created and if file already exists
then contents of file is erased.
“​r​” – File is opened for read only.
“​a​” – File is opened for write only. File pointer points to end of file. Existing data in file is
preserved.
“​w+​” – Opens file for read and write. If file not exist then new file is created and if file already
exists then contents of file is erased.
“​r+​” – File is opened for read/write.
“​a+​” – File is opened for write/read. File pointer points to end of file. Existing data in file is
preserved. If file is not there then new file is created.
“​x​” – New file is created for write only.
2) ​fread() –– After file is opened using fopen() the contents of data are read using fread(). It
takes two arguments. One is file pointer and another is file size in bytes, e.g.,
<?php
$filename = "demo.txt";
$file = fopen( $filename, 'r' );
$size = filesize( $filename );
$filedata = fread( $file, $size );
?>
3) ​fwrite() – New file can be created or text can be appended to an existing file using fwrite()
function. Arguments for fwrite() function are file pointer and text that is to written to file. It can
contain optional third argument where length of text to written is specified, e.g.,
<?php
$file = fopen("demo.txt", 'w');
$text = "Hello world\n";
fwrite($file, $text);
?>
4) ​fclose() – file is closed using fclose() function. Its argument is file which needs to be closed,
e.g.,
<?php

GURPREET SINGH BEDI ROLL NO-56463


$file = fopen("demo.txt", 'r');
//some code to be executed
fclose($file);
?>

GURPREET SINGH BEDI ROLL NO-56463

You might also like