Server Side Scripting Language
10/29/2019By Girmachew Gulint (Mtech CSE) 1
A typical web server today contains four elements
in addition to the physical hardware.
LAMP (Linux, Apache, MySQL, and PHP)
WAMP (Windows, Apache, MySQL, & PHP)
XAMPP (Apache, MariaDB , Perl and PHP)
 PHP
 ASP
 Perl
PHP( Personal Home Page/Hypertext Preprocessor )
• Created in 1994 at the hands of Rasmus Lerdorf.
• a server-side language, which means it runs on the server before anything is sent to
the user’s computer.
Some advantages of server-side language
• Code is hidden from the user
• Secure what is take place in the background
• Reduce users computer load even through it needs powerful server.
10/29/2019By Girmachew Gulint (Mtech CSE) 2
WHY PHP
• PHP runs on numerous, varying platforms, including Windows, Linux, Unix, Mac
OS X, and so on.
• PHP is compatible with almost any modern server, such as Apache, IIS, and more.
• PHP supports a wide range of databases.
• PHP is free!
• PHP is easy to learn and runs efficiently on the server side.
• PHP is faster than other scripting language e.g. asp and jsp.
10/29/2019By Girmachew Gulint (Mtech CSE) 3
Syntax
Tag style Starting tag Ending tag
Standard <?php ?>
Short hand <? ?>
ASP <% %>
Script <script language=“php> </script>
10/29/2019By Girmachew Gulint (Mtech CSE) 4
php can be saved .php or embeded into html.
Example
• <?php
• echo “Hello world”;
• ?>
10/29/2019By Girmachew Gulint (Mtech CSE) 5
• <?
• echo “Hello world”;
• ?>
• <%
• echo “Hello world”;
• %>
PHP-Errors
1. Notice: noticing the programmer.
2. Warning : something has gone wrong during the execution of a script.
3. Error : unrecoverable(execution will stop); typically parsing error like
missing semicolon, function or other problem the engine does not know
how to resolve. Another category of error is logical error.
10/29/2019By Girmachew Gulint (Mtech CSE) 6
Send output to the browser
With PHP, there are two basic ways to get output: echo and print.
1. echo;
2. print();
• The differences : echo has no return value while print has a return value of
1 so it can be used in expressions.
• echo can take multiple parameters (although such usage is rare) while print
can take one argument. echo is marginally faster than print.
10/29/2019By Girmachew Gulint (Mtech CSE) 7
Comment
1. // single line comment
2. # this is also single line comment
3. /* multi line comment */
10/29/2019By Girmachew Gulint (Mtech CSE) 8
Variables
• Are special container of user defined values. Values can be number, string or
Boolean or other.
• Variables use to create template for operation.
• Variable consist name of your choosing preceded by $. (meaningful)
• Variable name can include letter, number and underscore but not include
space
• Variable must start by underscore or letter only
10/29/2019By Girmachew Gulint (Mtech CSE) 9
Example
Good variable Bad variable
$name $1name
$age $+age
$firstName $first name
$_salary $1a2a3a
10/29/2019By Girmachew Gulint (Mtech CSE) 10
Availability of variables
1. Local : their life time is inside function only.
2. global/ superglobal : accessible globally or superglobally.
10/29/2019By Girmachew Gulint (Mtech CSE) 11
Data types
• Different types of data take up different amounts of memory and may be
treated differently when they are manipulated in a script.
• Some programming languages therefore demand that the programmer
declare in advance which type of data a variable will contain. By contrast,
PHP is loosely typed, meaning that it will calculate data types as data is
assigned to each variable.
10/29/2019By Girmachew Gulint (Mtech CSE) 12
Continued
PHP supports 8 primitive data types that can be categorized further in 3 types:
• Scalar Types
• Compound Types
• Special Types
10/29/2019By Girmachew Gulint (Mtech CSE) 13
Data types
Scala data types Compound data types Special data types
Boolean Array Resource
Integer Object Null
Float
Double
String
10/29/2019By Girmachew Gulint (Mtech CSE) 14
gettype() and settype() or casting
• $name = “Girmachew “;
• gettype($name);// will output String
• //casting data type
• $number = 4.5;
• echo gettype($number);
• settype($number, 'string'); // converting into string
• echo gettype($number);
10/29/2019By Girmachew Gulint (Mtech CSE) 15
Constant
PHP constants are name or identifier that can't be changed during the
execution of the script. PHP constants can be defined by 2 ways:
• Using define() function
• Using const keyword
• PHP constants follow the same PHP variable rules. For example, it can be
started with letter or underscore only.
• Conventionally, PHP constants should be defined in uppercase letters.
10/29/2019By Girmachew Gulint (Mtech CSE) 16
PHP constant: define()
• Let's see the syntax of define() function in PHP.
define(name, value, case-insensitive)
Example
• <?php
• define("MESSAGE","Hello JavaTpoint PHP");
• echo MESSAGE;
• ?>
10/29/2019By Girmachew Gulint (Mtech CSE) 17
PHP constant: const keyword
• The const keyword defines constants at compile time. It is a language construct not a function.
• It is bit faster than define().
• It is always case sensitive.
• Example
• <?php
• const MESSAGE="Hello const by JavaTpoint PHP";
• echo MESSAGE;
• ?>
10/29/2019By Girmachew Gulint (Mtech CSE) 18

Server side scripting language

  • 1.
    Server Side ScriptingLanguage 10/29/2019By Girmachew Gulint (Mtech CSE) 1 A typical web server today contains four elements in addition to the physical hardware. LAMP (Linux, Apache, MySQL, and PHP) WAMP (Windows, Apache, MySQL, & PHP) XAMPP (Apache, MariaDB , Perl and PHP)  PHP  ASP  Perl
  • 2.
    PHP( Personal HomePage/Hypertext Preprocessor ) • Created in 1994 at the hands of Rasmus Lerdorf. • a server-side language, which means it runs on the server before anything is sent to the user’s computer. Some advantages of server-side language • Code is hidden from the user • Secure what is take place in the background • Reduce users computer load even through it needs powerful server. 10/29/2019By Girmachew Gulint (Mtech CSE) 2
  • 3.
    WHY PHP • PHPruns on numerous, varying platforms, including Windows, Linux, Unix, Mac OS X, and so on. • PHP is compatible with almost any modern server, such as Apache, IIS, and more. • PHP supports a wide range of databases. • PHP is free! • PHP is easy to learn and runs efficiently on the server side. • PHP is faster than other scripting language e.g. asp and jsp. 10/29/2019By Girmachew Gulint (Mtech CSE) 3
  • 4.
    Syntax Tag style Startingtag Ending tag Standard <?php ?> Short hand <? ?> ASP <% %> Script <script language=“php> </script> 10/29/2019By Girmachew Gulint (Mtech CSE) 4 php can be saved .php or embeded into html.
  • 5.
    Example • <?php • echo“Hello world”; • ?> 10/29/2019By Girmachew Gulint (Mtech CSE) 5 • <? • echo “Hello world”; • ?> • <% • echo “Hello world”; • %>
  • 6.
    PHP-Errors 1. Notice: noticingthe programmer. 2. Warning : something has gone wrong during the execution of a script. 3. Error : unrecoverable(execution will stop); typically parsing error like missing semicolon, function or other problem the engine does not know how to resolve. Another category of error is logical error. 10/29/2019By Girmachew Gulint (Mtech CSE) 6
  • 7.
    Send output tothe browser With PHP, there are two basic ways to get output: echo and print. 1. echo; 2. print(); • The differences : echo has no return value while print has a return value of 1 so it can be used in expressions. • echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print. 10/29/2019By Girmachew Gulint (Mtech CSE) 7
  • 8.
    Comment 1. // singleline comment 2. # this is also single line comment 3. /* multi line comment */ 10/29/2019By Girmachew Gulint (Mtech CSE) 8
  • 9.
    Variables • Are specialcontainer of user defined values. Values can be number, string or Boolean or other. • Variables use to create template for operation. • Variable consist name of your choosing preceded by $. (meaningful) • Variable name can include letter, number and underscore but not include space • Variable must start by underscore or letter only 10/29/2019By Girmachew Gulint (Mtech CSE) 9
  • 10.
    Example Good variable Badvariable $name $1name $age $+age $firstName $first name $_salary $1a2a3a 10/29/2019By Girmachew Gulint (Mtech CSE) 10
  • 11.
    Availability of variables 1.Local : their life time is inside function only. 2. global/ superglobal : accessible globally or superglobally. 10/29/2019By Girmachew Gulint (Mtech CSE) 11
  • 12.
    Data types • Differenttypes of data take up different amounts of memory and may be treated differently when they are manipulated in a script. • Some programming languages therefore demand that the programmer declare in advance which type of data a variable will contain. By contrast, PHP is loosely typed, meaning that it will calculate data types as data is assigned to each variable. 10/29/2019By Girmachew Gulint (Mtech CSE) 12
  • 13.
    Continued PHP supports 8primitive data types that can be categorized further in 3 types: • Scalar Types • Compound Types • Special Types 10/29/2019By Girmachew Gulint (Mtech CSE) 13
  • 14.
    Data types Scala datatypes Compound data types Special data types Boolean Array Resource Integer Object Null Float Double String 10/29/2019By Girmachew Gulint (Mtech CSE) 14
  • 15.
    gettype() and settype()or casting • $name = “Girmachew “; • gettype($name);// will output String • //casting data type • $number = 4.5; • echo gettype($number); • settype($number, 'string'); // converting into string • echo gettype($number); 10/29/2019By Girmachew Gulint (Mtech CSE) 15
  • 16.
    Constant PHP constants arename or identifier that can't be changed during the execution of the script. PHP constants can be defined by 2 ways: • Using define() function • Using const keyword • PHP constants follow the same PHP variable rules. For example, it can be started with letter or underscore only. • Conventionally, PHP constants should be defined in uppercase letters. 10/29/2019By Girmachew Gulint (Mtech CSE) 16
  • 17.
    PHP constant: define() •Let's see the syntax of define() function in PHP. define(name, value, case-insensitive) Example • <?php • define("MESSAGE","Hello JavaTpoint PHP"); • echo MESSAGE; • ?> 10/29/2019By Girmachew Gulint (Mtech CSE) 17
  • 18.
    PHP constant: constkeyword • The const keyword defines constants at compile time. It is a language construct not a function. • It is bit faster than define(). • It is always case sensitive. • Example • <?php • const MESSAGE="Hello const by JavaTpoint PHP"; • echo MESSAGE; • ?> 10/29/2019By Girmachew Gulint (Mtech CSE) 18