0% found this document useful (0 votes)
49 views

Why The Lucky Stif

This document provides an overview of web scripting languages. It discusses syntax, properties of syntactic knowledge, and the relationship between syntax and meaning. It then introduces scripting languages and provides examples of Hello World programs in C++, Java, PHP, HTML, and C#. The document discusses web scripting and provides examples of JavaScript code. It also discusses server-side and client-side languages like PHP, JavaScript, and how they are used. Finally, it compares static and dynamic web models and how client and server processing differs between JavaScript and PHP.

Uploaded by

joshua lim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Why The Lucky Stif

This document provides an overview of web scripting languages. It discusses syntax, properties of syntactic knowledge, and the relationship between syntax and meaning. It then introduces scripting languages and provides examples of Hello World programs in C++, Java, PHP, HTML, and C#. The document discusses web scripting and provides examples of JavaScript code. It also discusses server-side and client-side languages like PHP, JavaScript, and how they are used. Finally, it compares static and dynamic web models and how client and server processing differs between JavaScript and PHP.

Uploaded by

joshua lim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

DESIGN AND IMPLEMENTATION OF PROGRAMMING

LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

when you don't create things, you become defined by your tastes rather than ability. your tastes only
narrow
&
exclude
people.
so
create.
Why The Lucky Stif

Recall for syntax


What is a syntax
When we concentrate on the structure & ordering of components within a sentence = studying
the syntax of a language
Syntax (originally Greek) = putting together/ arrangement
Syntax is the study of the rules governing the way words are combined to form sentences in a
language.

Properties of syntactic knowledge


Humans can understand & produce an infinite number of sentences they never heard before

Some purple gnats are starting to tango on microwave

Our grammar can understand and produce long sentences

Bill said that he thought that the esteemed leader of the house had it in mind to
tell the unfortunate vice president that the calls that he made from the office in the
White House that he thought was private..

Determine the grammatical relations in a sentence

Mary hired Bill Vs. Bill hired Mary

Syntax & meaning


Non-sense sentences with clear syntax
Colorless green ideas sleep comfortably.
A verb crumpled the milk.
I gave the question an angry egg.
* Comfortably sleep ideas green colorless.
* Milk the crumpled verb a.
* the question I an gave egg angry.
Sentences are composed of discrete units that are combined by rules. These rules explain how
speakers can store infinite knowledge in a finite space - brain.

ADRIAN D. EVANCULLA, MIT

WEEK # 3

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

Scripting Languages
Scripting is about producing simple very-high-level-languages that are friendly to the
programmer who has a life.
Modern sophisticated HLLS
Java, C++, C#, etc. are extremely complex
(they have a nasty tendency to get bigger and bigger as designers add more and more useful
facilities, and interface components, and bells and whistles, )
Take a long time to learn to use (but are wonderful when you really understand them).
Modern sophisticated HLLS Java, C++, C#, etc. are extremely complex
(they have a nasty tendency to get bigger and bigger as designers add more and more useful
facilities, and interface components, and bells and whistles, )
Take a long time to learn to use (but are wonderful when you really understand them).
In this example below there are four type of programming one is the c++
programming language, java programming, HTML and the other one is PHP programming,
As we can see the syntax and approach to display the output
Source Code

Filename extencion

Using namespace std;


Int main(){
cout<<Hello World;
return 0;
}
Public class HelloWorld{
Public static void main (String[]
args){
System.out.println(Hello
World!!);
}
}
<?php
Echo Hello World;
?>
<html>
<body>
Hello World
</body>
</html>
// A Hello World! program in
C#.

Automatically
save
as
Filename.cpp

Programming Type
C++ PROGRAMMING

JAVA PROGRAMMING

HYPERTEXT
PROCESSOR

PRE

HTML (Hyper Text Markup


Language)

C# PROGRAMMIN

save as
Filename.java

save as
Filename.php
save as
Filename.html

Save as
Filename

ADRIAN D. EVANCULLA, MIT

WEEK # 3

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello
World!");
// Keep the console
window open in debug mode.
Console.WriteLine("Press
any
key to exit.");
Console.ReadKey();
}
}
}
All program output the same word which is HELLO WORLD.

There are many scripting languages:


Python, perl, R, javascript, PHP
Some scripting languages are used primarily in web systems.
Some are self-standing languages. However, others are embedded in HTML and used to
enhance web pages.
Sample Code for script in javascript

Web Scripting

ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

Web sites and the web pages that they are composed of must be written using one or more
computer languages that web browsers can understand. Let's take a brief introduction to the
concept of web languages by looking at some of the most common ones.
HTML, XHTML, and CSS

The most commonly used and broadly applicable web language is HTML, which stands
forHyperText Markup Language. In this course we'll actually be learning HTML's smarter
descendant, XHTML (the X is for eXtensible).
As its title reveals, XHTML is a markup language, not a programming language. While
programming languages logically process data or information for various dynamic results, a
markup language simply "marks" bits and pieces of information as a means of identifying that
information. XHTML is what we use to prepare our content for the user. Rest assured that before
we're halfway through this course you will know XHTML inside and out.
While most web browsers perform some basic visual formatting of HTML de facto, we will need to
rely upon CSS, or Cascading Style Sheets to make our pages look awesome. CSS is the
formatting language that controls how the content that we identified with XHTML looks in a web
browser.
Client-Side Languages

Javascript is the ubiquitous web scripting language that runs on the client-side. This means
that everything Javascript does, it does using the user's web browser. Javascript is used to
enhance user interactivity within web pages, and can change the way a web page looks and acts
at any time, based on user input.

The other (complementary) approach is to do the work on the client machine.


Again we have extra code in the HTML, but now it is executed by the users browser (i.e. clientside).
Most common client side script is Javascript.
-An example of its use is when a web page has a form. We can use Javascript to validate the
input data client-side before it is sent to a server.
ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

-If we do the validation on the client, this reduces the work that the server has to do and reduces
the time taken to respond to the user.
HTML5 essentially includes Javascript elements to enhance its power.

Cascading Style Sheets / HTML


<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This page has a light blue background color!
</p>

Ouput

</body>
</html>

Both XHTML and CSS are delivered from the host web server to the client web browser once:
when the page loads. Unless acted upon by another web language, once XHTML and CSS for a
given page is loaded, it will remain static.

Server-Side Languages

While Javascript is a client-side web language, there are a number of powerful server-side web
languages, such as PHP, ASP, PERL, etc. Server-side languages allow the client web browser to
receive custom information and interactions on the fly through dynamic communication with the
web server. Server-side languages often "talk" to databases in order to store and retrieve user
information (e.g. shopping carts, searchable databases, etc).
PHP
<?php
$servername

Output
Connect Successfully
= "localhost";
ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

$username
$password
//
$conn
$username,

= "username";
= "password";
Create
connection
= new mysqli($servername,
$password);

//
Check
if ($conn->connect_error) {
die("Connection
failed:
>connect_error);
}
echo "Connected
?>

connection
".

$conn-

successfully";

Note: This sample will just work considering you have the localhost which is xampp and
username of your xampp and password you use to connect to xampp server follow instruction in
xampp in module 1.

Two important examples are:


Web Servers
Database Servers
Some of these machines may be powerful computers dedicated to the task, i.e Database server
A web server is a machine holding and delivering HTML pages that can be accessed by remote
(client) machines over the Internet.

Static Web Browser

You (the client) send a request to the server for a web page. The server looks up the web page
using part of the URL you have sent it, then returns the HTML page which your browser
subsequently displays on your machine.

Let us now consider a more dynamic model.


ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

You (the client) send a request to the server and it dynamically determines the HTML that is to
be returned.
The dynamics of the reply is achieved through extending the web server with a program (script)
that does some data processing and creates HTML output based on the data you sent (e.g.
contents of a form).
The process of generating the HTML response is performed server-side.
Dynamic Web Model
One approach is the Common Gateway Interface (CGI) where we have a separate program that
can be executed

Dynamic Web Model Continue


An alternative is to have extra code in the HTML that can be executed on the server to
determine the HTML that is to be returned.
That is how PHP works.

Client and Server


Note that we have HTML in which we have an embedded script that is to be executed.
There are clear similarities both in terms of the syntax and in how they are used.
However, there is one important difference:
ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

the PHP script is executed on the web server


theJavascript is executed by the browser on the client s machine
. The page with Javascript goes in an ordinary xx.html file while the page with PHP goes in an
xx.php file.
Accessing databases
These simple examples have shown how information can be sent from the client to the server
and how the server can dynamically create a web page that is to be returned.
In practice, the server will do a lot more processing.
Typically, the server will access a database and will either update the database or retrieve
information from it. That information is then used in the creation of the dynamic web page.
Overview
Some core features of programming languages:
1. Basic (built-in) types.
2. Strings (and string handling including pattern matching)
3. Data structures (associative arrays, but also abstract data types).
4. Control structures.
5. Modular programming.
6. Type regime.
7. Operating environment.

ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

Laboratory
The if, elseif ...else and switch statements are used to take decision based on the
different condition.
You can use conditional statements in your code to make your decisions. PHP supports
following three decision making statements

if...else statement use this statement if you want to execute a set of code when a
condition is true and another if the condition is not true

elseif statement is used with the if...else statement to execute a set of code if one of the
several condition is true

ADRIAN D. EVANCULLA, MIT

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

switch statement is used if you want to select one of many blocks of code to be executed,
use the Switch statement. The switch statement is used to avoid long blocks of if..elseif..else
code.

The If...Else Statement


If you want to execute some code if a condition is true and another code if a condition is
false, use the if....else statement.

Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;

Example
The following example will output "Have a nice weekend!" if the current day is Friday,
Otherwise, it will output "Have a nice day!":
<html>
<body>

<?php
$d =date("D");

if($d =="Fri")
echo"Have a nice weekend!";

else
echo"Have a nice day!";
?>

</body>

ADRIAN D. EVANCULLA, MIT

10

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

</html>

It will produce the following result

The ElseIf Statement


If you want to execute some code if one of the several conditions are true use the elseif
statement

Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;

Example
The following example will output "Have a nice weekend!" if the current day is Friday,
and "Have a nice Sunday!" if the current day is Sunday. Otherwise, it will output "Have a
nice day!"
<html>
<body>
<?php
$d =date("D");
if($d =="Fri")
echo"Have a nice weekend!";
elseif($d =="Sun")
echo"Have a nice Sunday!";
else
echo"Have a nice day!";
?>
</body>

ADRIAN D. EVANCULLA, MIT

11

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

</html>

It will produce the following result

The Switch Statement


If you want to select one of many blocks of code to be executed, use the Switch
statement.
The switch statement is used to avoid long blocks of if..elseif..else code.

Syntax
switch (expression){
caselabel1:
code to be executed if expression = label1;
break;

caselabel2:
code to be executed if expression = label2;
break;
default:

code to be executed
if expression is different
from both label1 and label2;
}

Example
The switch statement works in an unusual way. First it evaluates given expression then
seeks a lable to match the resulting value. If a matching value is found then the code
associated with the matching label will be executed or if none of the lable matches then
statement will execute any specified default code.
<html>
<body>

ADRIAN D. EVANCULLA, MIT

12

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

<?php
$d =date("D");

switch($d){
case"Mon":
echo"Today is Monday";
break;

case"Tue":
echo"Today is Tuesday";
break;

case"Wed":
echo"Today is Wednesday";
break;

case"Thu":
echo"Today is Thursday";
break;

case"Fri":
echo"Today is Friday";
break;

case"Sat":
echo"Today is Saturday";
break;

case"Sun":
echo"Today is Sunday";

ADRIAN D. EVANCULLA, MIT

13

DESIGN AND IMPLEMENTATION OF PROGRAMMING


LANGUAGE
MODULE

WEEK # 3

Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab

break;

default:
echo"Wonder which day is this ?";
}
?>

</body>
</html>

It will produce the following result


Today is Friday

Laboratory
Activity # 1

ADRIAN D. EVANCULLA, MIT

14

You might also like