SlideShare a Scribd company logo
1 of 22
Chapter One:
Server Side
Scripting Basics
11/28/2019
BantamlakDejene,Information
Technology
1
Introduction to Server-Side Scripting
Today’s Web users expect exciting pages that are updated
frequently and provide a customized experience. For them, Web
sites are more like communities, to which they’ll return time
and again. At the same time, Web-site administrators want sites
that are easier to update and maintain, understanding that’s the
only reasonable way to keep up with visitors’ expectations. For
these reasons and more, PHP and MySQL have become the de
facto standards for creating dynamic, database driven Web sites.
11/28/2019
BantamlakDejene,Information
Technology
2
Cont.
.
Dynamic Web sites are flexible and potent creatures, more accurately
described as applications than merely sites. Dynamic Web sites
Respond to different parameters (for example, the time of day or the
version of the visitor’s Web browser)
Have a “memory,” allowing for user registration and login, e-commerce,
and similar processes
Almost always integrate HTML forms, allowing visitors to perform
searches, provide feedback, and so forth
Often have interfaces where administrators can manage the site’s content
Are easier to maintain, upgrade, and build upon than statically made sites.
11/28/2019
BantamlakDejene,Information
Technology
3
Cont.
.
There are many technologies available for creating dynamic
Web sites. The most common are ASP.NET (Active Server
Pages, a Microsoft construct), JSP (Java Server Pages),
ColdFusion, Ruby on Rails (a Web development framework
for the Ruby programming language), and PHP. Dynamic
Web sites don’t always rely on a database, but more and
more of them do, particularly as excellent database
applications like MySQL are available at little to no cost.
11/28/2019
BantamlakDejene,Information
Technology
4
Server-Side Scripting Languages
PHP originally stood for “Personal Home Page” as it was created in 1994 by Rasmus
Lerdorf to track the visitors to his online résumé. As its usefulness and capabilities
grew, it came to mean “PHP: Hypertext Preprocessor. According to the official PHP
Web site, found at www.php.net A, PHP is a “widely used general-purpose scripting
language that is especially suited for Web development and can be embedded into
HTML.” It’s a long but descriptive definition.
Server side refers to the fact that everything PHP does occurs on the server. A Web
server application, like Apache or Microsoft’s IIS, is required and all PHP scripts
must be accessed through a URL. Its cross-platform nature means that PHP runs on
most operating systems, including Windows, UNIX, and Macintosh. More important,
the PHP scripts written on one server will normally work on another with little or no
modification.
11/28/2019
BantamlakDejene,Information
Technology
5
Cont.
.
MySQL (www.mysql.com) is the world’s most popular open-source database. In
fact, today MySQL is a viable competitor to the pricey goliaths such as Oracle and
Microsoft’s SQL Server. Like PHP, MySQL offers excellent performance,
portability, and reliability, with a moderate learning curve and little to no cost.
MySQL is an RDBMS. A database, in the simplest terms, is a collection of data, be
it text, numbers, or binary files, stored and kept organized by the DBMS.
MySQL is an open-source application, like PHP, meaning that it is free to use or
even modify. There are occasions in which you should pay for a MySQL license,
especially if you are making money from the sales or incorporation of the MySQL
product. The MySQL software consists of several pieces, including the MySQL
server, the MySQL client, and numerous utilities for maintenance and other
purposes. PHP always had good support for MySQL, and that is even truer in the
most recent versions of the language.
11/28/2019
BantamlakDejene,Information
Technology
6
Use Basic Syntax
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Title</title></head>
<body><!-- Example 1 - template.html -->
</body></html>
11/28/2019
BantamlakDejene,Information
Technology
7
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic PHP Page</title></head>
<body><!—Example 2 - first.php -->
<p>This is standard HTML.</p><?php?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
8
Send Data to Web Browser
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
<title>Using Echo</title></head>
<body><!-- Example 3 - second.php -->
<p>This is standard HTML.</p>
<?php
echo <p>This is generated by using PHP!</p>
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
9
Write Comments
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comments</title></head>
<body><?php
# Example 4 - comments.php
# Created March 16, 2011
# Created by Larry E. Ullman
# This script does nothing much.
echo '<p>This is a line of text.<br />
This is another line of text.</p>';
/*
echo 'This line will not be executed.';
*/
echo "<p>Now I'm done.</p>";
// End of PHP code.
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
10
Utilize Variables
Regardless of what type you are creating, all variable names in
PHP follow certain syntactical rules:
A variable’s name must start with a dollar sign ($), for example, $name.
The variable’s name can contain a combination of letters, numbers, and
the underscore, for example, $my_report1.
The first character after the dollar sign must be either a letter or an
underscore (it cannot be a number).
Variable names in PHP are case sensitive! This is a very important rule. It
means that $name and $Name are entirely different variables.
11/28/2019
BantamlakDejene,Information
Technology
11
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN“
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Predefined Variables</title></head>
<body><?php # Example 5 - predefined.php
// Create a shorthand version of the variable names:
$file = $_SERVER['SCRIPT_FILENAME'];
$user = $_SERVER['HTTP_USER_AGENT'];
$server = $_SERVER['SERVER_SOFTWARE'];
// Print the name of this script:
echo "<p>You are running the file:<br /><b>$file</b>.</p>n";
// Print the user's information:
echo "<p>You are viewing this page using:<br /><b>$user</b></p>n";
// Print the server's information:
echo "<p>This server is running: <br /><b>$server</b>.</p>n";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
12
Manipulate Strings
A string is merely a quoted chunk of characters: letters, numbers, spaces, punctuation, and so
forth. These are all strings:
-> ‘Tobias’ -> “In watermelon sugar” -> ‘100’ -> ‘August 2, 2011
Make a string variable, assign a string value to a valid variable name:
$first_name = 'Tobias'; $today = 'August 2, 2011';
When creating strings, you can use either single or double quotation marks to encapsulate the characters,
just as you would when printing text. Likewise, you must use the same type of quotation mark for the
beginning and the end of the string. If that same mark appears within the string, it must be escaped: $var =
"Define "platitude", please."; Or you can also use the other quotation mark type: $var = 'Define
"platitude", please.';
To print out the value of a string, use either
echo or print:
echo $first_name
To print the value of string within a context, you must use double quotation marks:
echo "Hello, $first_name";
11/28/2019
BantamlakDejene,Information
Technology
13
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # Example6 - strings.php
// Create the variables:
$first_name = 'ሐá‹Čሔ';
$last_name = 'አለማሁ';
$book = 'ፍቅር ኄሔኚ መቃቄር';
// Print the values:
echo "<p>The book <em>$book</em> was written by $first_name $last_name.</p>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
14
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string concatenation, length and word counting =>
string_concat.php
// Create the variables:
$favoriteAnimal = 'cat';
$myArray ['age']= '28';
$about = "My age";
$len = strlen($about);
$word = str_word_count("My favorite animals are {$favoriteAnimal}s");
// Print the values:
echo "My favorite animals are {$favoriteAnimal}s => There are {$word} words in
this sentence</br>"; // using curly bracket
echo $about . " is " . $myArray["age"] . "</br>"; // using . operator
echo "The length of " . $about . " is " . $len;
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
15
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string search and count => string_search.php
// Create the variables:
$su = 'Welcome to Samara University. Welcome to Department of Information Technology <br>
This is the Department of Information Technology from College of Engineering and Technology in Samara University';
$search = strstr($su, "Engineering");// searches the string from the sentence
$searchF = strpos($su, "University");// locates the string starting from beginning
$searchE = strrpos($su, "Samara");// locates the string starting from end
$count = substr_count($su, "Technology");//counts the repetition of the string in the text
$countS = substr_count($su, "to", 9);//counts the repetition of the string in the text starting form the given index
$countF = substr_count($su, "of", 45, 100);//counts the repetition of the string in the text between the indexes
// Print the values:
echo $su . "</br>";
echo "</br>Engineering is found at => ". $search . "</br>";
echo "University is found at => " . $searchF . " => from the beginning </br>";
echo "Samara is found at => " . $searchE . " => from the end </br>";
echo "Technology is repeated => " . $count . " => times in the text </br>";
echo "to is repeated => " . $countS . " => times in the text starting from index 9 </br>";
echo "of is repeated => " . $countF . " => times in the text between index 45 and 100 </br>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
16
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string manipulation => string_manipulation.php
// Create the variables:
$myString = "It was the best of times, it was the worst of times";
$string = "Here's a little string";
$str = "Information Technology";
echo $myString . "</br></br>";
echo str_replace("times", "bananas", $myString, $num ). "</br>";//replaces all and count it
echo "The text was replaced $num times. </br></br>";
echo substr_replace($myString, "bananas", 11 ). "</br></br>";//replaces from the given index
echo substr_replace($myString, "bananas", 19, 5). "</br></br>";//replaces from the given index to the given number of characters
echo substr_replace($myString, "really", 3, 0) . "</br></br>";
echo strtr($myString, " '", "+-"). "</br></br>";
echo strtolower($str) . "</br></br>";
echo ucfirst($str) . "</br></br>";
echo lcfirst($str) . "</br></br>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
17
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Type Specifiers in Action</title >
<link rel="stylesheet" type="text/css" href="common.css"></head>
<body><h1>Type Specifiers in Action</h1>
<?php
$myNumber = 123.45;
printf("Binary: %b </br>", $myNumber);
printf("Character: %c </br>", $myNumber);
printf("Decimal: %d </br>", $myNumber);
printf("Scientific: %e </br>", $myNumber);
printf("Float: %f </br>", $myNumber );
printf("Octal: %o </br>", $myNumber );
printf("String: %s </br>", $myNumber );
printf("Hex (lower case): %x </br>", $myNumber );
printf("Hex (upper case): %X </br>", $myNumber );
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
18
Manipulate Numbers Work with Constants
PHP has both integer and floating-point (decimal) number types. These two types can be
classified under the generic title numbers without losing any valuable distinction (for the most
part). Valid number-type variables in PHP can be anything like
-> 8 -> 3.14 -> 10980843985 -> -4.2398508 -> 4.4e2
Notice that these values are never quoted—quoted numbers are strings with neither numeric
values— nor do they include commas to indicate thousands. Also, a number is assumed to be
positive unless it is preceded by the minus sign (-). Along with the standard arithmetic
operators
you can use on numbers (Table 1.1), there are dozens of functions built into PHP. Two
common ones are round( ) and number_format( ). The former rounds a decimal to the
nearest integer:
$n = 3.14;
$n = round ($n); // 3
11/28/2019
BantamlakDejene,Information
Technology
19
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Numbers</title></head><body>
<?php # Script 1.8 - numbers.php
// Set the variables:
$quantity = 30; // Buying 30 widgets.
$price = 119.95;
$taxrate = .05; // 5% sales tax.
// Calculate the total:
$total = $quantity * $price;
$total = $total + ($total * $taxrate);
// Calculate and add the tax.
// Format the total:
$total = number_format ($total, 2);
// Print the results:
echo "<p/>You are purchasing </br>" . $quantity . "</br> widget(s) at a cost of <br>$" . $price .
"</br> each. With tax, the total comes to <b>$" . $total . ".</br></p>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
20
Cont.
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Constants</title></head><body>
<?php # Script 1.9 - constants.php
// Set today's date as a constant:
define ('TODAY', 'March 16, 2011');
// Print a message, using predefined constants and the TODAY constant:
echo '<p>Today is ' . TODAY . '.</br> This server is running version <b>' . PHP_VERSION .
'</b>
of PHP on the <b>' . PHP_OS . '</b> operating system.</p>';
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
21
THANK YOU
11/28/2019
BantamlakDejene,Information
Technology
22

More Related Content

What's hot

C5 Javascript
C5 JavascriptC5 Javascript
C5 JavascriptVlad Posea
 
PHP form tutorial
PHP form tutorialPHP form tutorial
PHP form tutorialPromb
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erickokelloerick
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basicsKumar
 
IPW HTML course
IPW HTML courseIPW HTML course
IPW HTML courseVlad Posea
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2Abhishek Kesharwani
 
What should or not be programmed on the web
What should or not be programmed on the  webWhat should or not be programmed on the  web
What should or not be programmed on the webMohammad Kamrul Hasan
 
Xml ppt
Xml pptXml ppt
Xml pptseemadav1
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xmlUma mohan
 
Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)azadmcs
 
Introduction to XHTML
Introduction to XHTMLIntroduction to XHTML
Introduction to XHTMLHend Al-Khalifa
 

What's hot (14)

Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
C5 Javascript
C5 JavascriptC5 Javascript
C5 Javascript
 
Xml
XmlXml
Xml
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
PHP form tutorial
PHP form tutorialPHP form tutorial
PHP form tutorial
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
 
IPW HTML course
IPW HTML courseIPW HTML course
IPW HTML course
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
What should or not be programmed on the web
What should or not be programmed on the  webWhat should or not be programmed on the  web
What should or not be programmed on the web
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xml
 
Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)
 
Introduction to XHTML
Introduction to XHTMLIntroduction to XHTML
Introduction to XHTML
 

Similar to server side scripting basics

PHP Basics
PHP BasicsPHP Basics
PHP BasicsRoohul Amin
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQLbmani
 
Php Tutorial
Php TutorialPhp Tutorial
Php TutorialSHARANBAJWA
 
Osp ii presentation
Osp ii presentationOsp ii presentation
Osp ii presentationpresse_jkp
 
1 Introduction to Drupal Web Development
1 Introduction to Drupal Web Development1 Introduction to Drupal Web Development
1 Introduction to Drupal Web DevelopmentWingston
 
Fundamentals of web_design_v2
Fundamentals of web_design_v2Fundamentals of web_design_v2
Fundamentals of web_design_v2hussain534
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics EbookSwanand Pol
 
Leksion 1 hyrje ne xhtml
Leksion 1   hyrje ne xhtmlLeksion 1   hyrje ne xhtml
Leksion 1 hyrje ne xhtmlmariokenga
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysqlProgrammer Blog
 
Web Programming introduction
Web Programming introductionWeb Programming introduction
Web Programming introductionAbdul-Rahman Mahmood
 
Web Development From the Ground Up, a Series for Novice ...
Web Development From the Ground Up, a Series for Novice ...Web Development From the Ground Up, a Series for Novice ...
Web Development From the Ground Up, a Series for Novice ...webhostingguy
 
Iwt module 1
Iwt  module 1Iwt  module 1
Iwt module 1SANTOSH RATH
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 
Introduction To Website Development
Introduction To Website DevelopmentIntroduction To Website Development
Introduction To Website Developmentzaidfarooqui974
 
Php intro
Php introPhp intro
Php introRajesh Jha
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web ApplicationSachin Walvekar
 

Similar to server side scripting basics (20)

PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Osp ii presentation
Osp ii presentationOsp ii presentation
Osp ii presentation
 
1 Introduction to Drupal Web Development
1 Introduction to Drupal Web Development1 Introduction to Drupal Web Development
1 Introduction to Drupal Web Development
 
Fundamentals of web_design_v2
Fundamentals of web_design_v2Fundamentals of web_design_v2
Fundamentals of web_design_v2
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics Ebook
 
phptutorial
phptutorialphptutorial
phptutorial
 
Leksion 1 hyrje ne xhtml
Leksion 1   hyrje ne xhtmlLeksion 1   hyrje ne xhtml
Leksion 1 hyrje ne xhtml
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysql
 
Web Programming introduction
Web Programming introductionWeb Programming introduction
Web Programming introduction
 
Web Development From the Ground Up, a Series for Novice ...
Web Development From the Ground Up, a Series for Novice ...Web Development From the Ground Up, a Series for Novice ...
Web Development From the Ground Up, a Series for Novice ...
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Iwt module 1
Iwt  module 1Iwt  module 1
Iwt module 1
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Introduction To Website Development
Introduction To Website DevelopmentIntroduction To Website Development
Introduction To Website Development
 
Php intro
Php introPhp intro
Php intro
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web Application
 

More from bantamlak dejene

object oriented fundamentals in vb.net
object oriented fundamentals in vb.netobject oriented fundamentals in vb.net
object oriented fundamentals in vb.netbantamlak dejene
 
introduction to .net
introduction to .netintroduction to .net
introduction to .netbantamlak dejene
 
introduction to vb.net
introduction to vb.netintroduction to vb.net
introduction to vb.netbantamlak dejene
 
html forms and server side scripting
html forms and server side scriptinghtml forms and server side scripting
html forms and server side scriptingbantamlak dejene
 
server side scripting basics by Bantamlak Dejene
server side scripting basics by Bantamlak Dejeneserver side scripting basics by Bantamlak Dejene
server side scripting basics by Bantamlak Dejenebantamlak dejene
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netbantamlak dejene
 
Vb ch 2-introduction_to_.net
Vb ch 2-introduction_to_.netVb ch 2-introduction_to_.net
Vb ch 2-introduction_to_.netbantamlak dejene
 
Vb ch 1-introduction
Vb ch 1-introductionVb ch 1-introduction
Vb ch 1-introductionbantamlak dejene
 

More from bantamlak dejene (8)

object oriented fundamentals in vb.net
object oriented fundamentals in vb.netobject oriented fundamentals in vb.net
object oriented fundamentals in vb.net
 
introduction to .net
introduction to .netintroduction to .net
introduction to .net
 
introduction to vb.net
introduction to vb.netintroduction to vb.net
introduction to vb.net
 
html forms and server side scripting
html forms and server side scriptinghtml forms and server side scripting
html forms and server side scripting
 
server side scripting basics by Bantamlak Dejene
server side scripting basics by Bantamlak Dejeneserver side scripting basics by Bantamlak Dejene
server side scripting basics by Bantamlak Dejene
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
 
Vb ch 2-introduction_to_.net
Vb ch 2-introduction_to_.netVb ch 2-introduction_to_.net
Vb ch 2-introduction_to_.net
 
Vb ch 1-introduction
Vb ch 1-introductionVb ch 1-introduction
Vb ch 1-introduction
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

server side scripting basics

  • 1. Chapter One: Server Side Scripting Basics 11/28/2019 BantamlakDejene,Information Technology 1
  • 2. Introduction to Server-Side Scripting Today’s Web users expect exciting pages that are updated frequently and provide a customized experience. For them, Web sites are more like communities, to which they’ll return time and again. At the same time, Web-site administrators want sites that are easier to update and maintain, understanding that’s the only reasonable way to keep up with visitors’ expectations. For these reasons and more, PHP and MySQL have become the de facto standards for creating dynamic, database driven Web sites. 11/28/2019 BantamlakDejene,Information Technology 2
  • 3. Cont.
. Dynamic Web sites are flexible and potent creatures, more accurately described as applications than merely sites. Dynamic Web sites Respond to different parameters (for example, the time of day or the version of the visitor’s Web browser) Have a “memory,” allowing for user registration and login, e-commerce, and similar processes Almost always integrate HTML forms, allowing visitors to perform searches, provide feedback, and so forth Often have interfaces where administrators can manage the site’s content Are easier to maintain, upgrade, and build upon than statically made sites. 11/28/2019 BantamlakDejene,Information Technology 3
  • 4. Cont.
. There are many technologies available for creating dynamic Web sites. The most common are ASP.NET (Active Server Pages, a Microsoft construct), JSP (Java Server Pages), ColdFusion, Ruby on Rails (a Web development framework for the Ruby programming language), and PHP. Dynamic Web sites don’t always rely on a database, but more and more of them do, particularly as excellent database applications like MySQL are available at little to no cost. 11/28/2019 BantamlakDejene,Information Technology 4
  • 5. Server-Side Scripting Languages PHP originally stood for “Personal Home Page” as it was created in 1994 by Rasmus Lerdorf to track the visitors to his online rĂ©sumĂ©. As its usefulness and capabilities grew, it came to mean “PHP: Hypertext Preprocessor. According to the official PHP Web site, found at www.php.net A, PHP is a “widely used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.” It’s a long but descriptive definition. Server side refers to the fact that everything PHP does occurs on the server. A Web server application, like Apache or Microsoft’s IIS, is required and all PHP scripts must be accessed through a URL. Its cross-platform nature means that PHP runs on most operating systems, including Windows, UNIX, and Macintosh. More important, the PHP scripts written on one server will normally work on another with little or no modification. 11/28/2019 BantamlakDejene,Information Technology 5
  • 6. Cont.
. MySQL (www.mysql.com) is the world’s most popular open-source database. In fact, today MySQL is a viable competitor to the pricey goliaths such as Oracle and Microsoft’s SQL Server. Like PHP, MySQL offers excellent performance, portability, and reliability, with a moderate learning curve and little to no cost. MySQL is an RDBMS. A database, in the simplest terms, is a collection of data, be it text, numbers, or binary files, stored and kept organized by the DBMS. MySQL is an open-source application, like PHP, meaning that it is free to use or even modify. There are occasions in which you should pay for a MySQL license, especially if you are making money from the sales or incorporation of the MySQL product. The MySQL software consists of several pieces, including the MySQL server, the MySQL client, and numerous utilities for maintenance and other purposes. PHP always had good support for MySQL, and that is even truer in the most recent versions of the language. 11/28/2019 BantamlakDejene,Information Technology 6
  • 7. Use Basic Syntax <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Page Title</title></head> <body><!-- Example 1 - template.html --> </body></html> 11/28/2019 BantamlakDejene,Information Technology 7
  • 8. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Basic PHP Page</title></head> <body><!—Example 2 - first.php --> <p>This is standard HTML.</p><?php?></body></html> 11/28/2019 BantamlakDejene,Information Technology 8
  • 9. Send Data to Web Browser <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Using Echo</title></head> <body><!-- Example 3 - second.php --> <p>This is standard HTML.</p> <?php echo <p>This is generated by using PHP!</p> ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 9
  • 10. Write Comments <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Comments</title></head> <body><?php # Example 4 - comments.php # Created March 16, 2011 # Created by Larry E. Ullman # This script does nothing much. echo '<p>This is a line of text.<br /> This is another line of text.</p>'; /* echo 'This line will not be executed.'; */ echo "<p>Now I'm done.</p>"; // End of PHP code. ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 10
  • 11. Utilize Variables Regardless of what type you are creating, all variable names in PHP follow certain syntactical rules: A variable’s name must start with a dollar sign ($), for example, $name. The variable’s name can contain a combination of letters, numbers, and the underscore, for example, $my_report1. The first character after the dollar sign must be either a letter or an underscore (it cannot be a number). Variable names in PHP are case sensitive! This is a very important rule. It means that $name and $Name are entirely different variables. 11/28/2019 BantamlakDejene,Information Technology 11
  • 12. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN“ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Predefined Variables</title></head> <body><?php # Example 5 - predefined.php // Create a shorthand version of the variable names: $file = $_SERVER['SCRIPT_FILENAME']; $user = $_SERVER['HTTP_USER_AGENT']; $server = $_SERVER['SERVER_SOFTWARE']; // Print the name of this script: echo "<p>You are running the file:<br /><b>$file</b>.</p>n"; // Print the user's information: echo "<p>You are viewing this page using:<br /><b>$user</b></p>n"; // Print the server's information: echo "<p>This server is running: <br /><b>$server</b>.</p>n"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 12
  • 13. Manipulate Strings A string is merely a quoted chunk of characters: letters, numbers, spaces, punctuation, and so forth. These are all strings: -> ‘Tobias’ -> “In watermelon sugar” -> ‘100’ -> ‘August 2, 2011 Make a string variable, assign a string value to a valid variable name: $first_name = 'Tobias'; $today = 'August 2, 2011'; When creating strings, you can use either single or double quotation marks to encapsulate the characters, just as you would when printing text. Likewise, you must use the same type of quotation mark for the beginning and the end of the string. If that same mark appears within the string, it must be escaped: $var = "Define "platitude", please."; Or you can also use the other quotation mark type: $var = 'Define "platitude", please.'; To print out the value of a string, use either echo or print: echo $first_name To print the value of string within a context, you must use double quotation marks: echo "Hello, $first_name"; 11/28/2019 BantamlakDejene,Information Technology 13
  • 14. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # Example6 - strings.php // Create the variables: $first_name = 'ሐá‹Čሔ'; $last_name = 'አለማሁ'; $book = 'ፍቅር ኄሔኚ መቃቄር'; // Print the values: echo "<p>The book <em>$book</em> was written by $first_name $last_name.</p>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 14
  • 15. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string concatenation, length and word counting => string_concat.php // Create the variables: $favoriteAnimal = 'cat'; $myArray ['age']= '28'; $about = "My age"; $len = strlen($about); $word = str_word_count("My favorite animals are {$favoriteAnimal}s"); // Print the values: echo "My favorite animals are {$favoriteAnimal}s => There are {$word} words in this sentence</br>"; // using curly bracket echo $about . " is " . $myArray["age"] . "</br>"; // using . operator echo "The length of " . $about . " is " . $len; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 15
  • 16. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string search and count => string_search.php // Create the variables: $su = 'Welcome to Samara University. Welcome to Department of Information Technology <br> This is the Department of Information Technology from College of Engineering and Technology in Samara University'; $search = strstr($su, "Engineering");// searches the string from the sentence $searchF = strpos($su, "University");// locates the string starting from beginning $searchE = strrpos($su, "Samara");// locates the string starting from end $count = substr_count($su, "Technology");//counts the repetition of the string in the text $countS = substr_count($su, "to", 9);//counts the repetition of the string in the text starting form the given index $countF = substr_count($su, "of", 45, 100);//counts the repetition of the string in the text between the indexes // Print the values: echo $su . "</br>"; echo "</br>Engineering is found at => ". $search . "</br>"; echo "University is found at => " . $searchF . " => from the beginning </br>"; echo "Samara is found at => " . $searchE . " => from the end </br>"; echo "Technology is repeated => " . $count . " => times in the text </br>"; echo "to is repeated => " . $countS . " => times in the text starting from index 9 </br>"; echo "of is repeated => " . $countF . " => times in the text between index 45 and 100 </br>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 16
  • 17. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string manipulation => string_manipulation.php // Create the variables: $myString = "It was the best of times, it was the worst of times"; $string = "Here's a little string"; $str = "Information Technology"; echo $myString . "</br></br>"; echo str_replace("times", "bananas", $myString, $num ). "</br>";//replaces all and count it echo "The text was replaced $num times. </br></br>"; echo substr_replace($myString, "bananas", 11 ). "</br></br>";//replaces from the given index echo substr_replace($myString, "bananas", 19, 5). "</br></br>";//replaces from the given index to the given number of characters echo substr_replace($myString, "really", 3, 0) . "</br></br>"; echo strtr($myString, " '", "+-"). "</br></br>"; echo strtolower($str) . "</br></br>"; echo ucfirst($str) . "</br></br>"; echo lcfirst($str) . "</br></br>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 17
  • 18. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>Type Specifiers in Action</title > <link rel="stylesheet" type="text/css" href="common.css"></head> <body><h1>Type Specifiers in Action</h1> <?php $myNumber = 123.45; printf("Binary: %b </br>", $myNumber); printf("Character: %c </br>", $myNumber); printf("Decimal: %d </br>", $myNumber); printf("Scientific: %e </br>", $myNumber); printf("Float: %f </br>", $myNumber ); printf("Octal: %o </br>", $myNumber ); printf("String: %s </br>", $myNumber ); printf("Hex (lower case): %x </br>", $myNumber ); printf("Hex (upper case): %X </br>", $myNumber ); ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 18
  • 19. Manipulate Numbers Work with Constants PHP has both integer and floating-point (decimal) number types. These two types can be classified under the generic title numbers without losing any valuable distinction (for the most part). Valid number-type variables in PHP can be anything like -> 8 -> 3.14 -> 10980843985 -> -4.2398508 -> 4.4e2 Notice that these values are never quoted—quoted numbers are strings with neither numeric values— nor do they include commas to indicate thousands. Also, a number is assumed to be positive unless it is preceded by the minus sign (-). Along with the standard arithmetic operators you can use on numbers (Table 1.1), there are dozens of functions built into PHP. Two common ones are round( ) and number_format( ). The former rounds a decimal to the nearest integer: $n = 3.14; $n = round ($n); // 3 11/28/2019 BantamlakDejene,Information Technology 19
  • 20. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Numbers</title></head><body> <?php # Script 1.8 - numbers.php // Set the variables: $quantity = 30; // Buying 30 widgets. $price = 119.95; $taxrate = .05; // 5% sales tax. // Calculate the total: $total = $quantity * $price; $total = $total + ($total * $taxrate); // Calculate and add the tax. // Format the total: $total = number_format ($total, 2); // Print the results: echo "<p/>You are purchasing </br>" . $quantity . "</br> widget(s) at a cost of <br>$" . $price . "</br> each. With tax, the total comes to <b>$" . $total . ".</br></p>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 20
  • 21. Cont.
. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Constants</title></head><body> <?php # Script 1.9 - constants.php // Set today's date as a constant: define ('TODAY', 'March 16, 2011'); // Print a message, using predefined constants and the TODAY constant: echo '<p>Today is ' . TODAY . '.</br> This server is running version <b>' . PHP_VERSION . '</b> of PHP on the <b>' . PHP_OS . '</b> operating system.</p>'; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 21