Experiment 14 Scripting
Experiment 14 Scripting
AIM : Illustrate the use of control statements in the server side script
THEORY :
Scripting language (also known as scripting, or script) is plainly defined as a series of commands
that are able to be executed without the need for compiling. While all scripting languages are
programming languages, not all programming languages are scripting languages. PHP, Perl, and
Python are common examples of scripting languages.
Scripting languages use a program known as an interpreter to translate commands and are directly
interpreted from source code, not requiring a compilation step. Other programming languages, on
the other hand, may require a compiler to translate commands into machine code before it can
execute those commands.
There are two types of scripting languages : server side and client side. The only significant
difference between the two is that the former requires a server for its processing.
Server-side scripting languages run on a web server. When a client sends a request, the server
responds by sending content via HTTP. In contrast, client-side scripting languages run on the client
end on their web browser.
The benefit of client-side scripts is that they can reduce demand on the server, allowing web pages
to load faster. Whereas, one significant benefit of server-side scripts is they are not viewable by the
public like client-side scripts are.
When trying to decide which way to go on a project, keep in mind that client-side scripting is more
focused on user interface and functionality. Conversely, server-side scripting focuses on faster
processing, access to data, and resolving errors.
There are many benefits to using scripting languages over other programming languages. First,
they are open-source. This allows users from around the world to join in the improvement process.
Other pros include :
There are not a whole lot of cons to using scripting languages. One con is the fact that some
companies don’t want scripts to be read by everyone, so they use server-side scripts to avoid
releasing them to the public. Also, installing an interpreter program can be a hassle. Finally,
sometimes scripts are slower than programs.
Like all other languages, PHP provides a few control statements enabling developers to develop
different logic to execute in different conditions. PHP core includes the control statements:
if
if else
if else if
Switch statement
Generally, the for loop is used to execute a piece of code a specific number of times. In other
words, if you already know the number of times you want to execute a block of code, it's
the for loop which is the best choice.
Syntax :
CODE :
OUTPUT:
CONCLUSION: