Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Web Technology for III BCA, Study notes of Web Application Development

PHP Scripting Languages: Introducing PHP – Basic development Concepts – Creating first PHP Scripts – Using Variable and Operators – Storing Data in variable – Understanding Data types – Setting and Checking variables Data types – Using Constants – Manipulating Variables with Operators. Controlling Program Flow: Writing Simple Conditional Statements - Writing More Complex Conditional Statements – Repeating Action with Loops – Working with String and Numeric Functions. Working with Arrays: Storing Data in Arrays – Processing Arrays with Loops and Iterations –Using Arrays with Forms - Working with Array Functions – Working with Dates and Times. Using Functions and Classes: Creating User-Defined Functions - Creating Classes – Using Advanced OOP Concepts. Working with Files and Directories: Reading Files-Writing Files Processing Directories. Working with Database and SQL: Introducing Database and SQL- Using MySQL-Adding and modifying Data-Handling Errors – Using SQLite Extension

Typology: Study notes

2020/2021

Uploaded on 12/18/2023

kanimozhi-suguna-s
kanimozhi-suguna-s 🇮🇳

1 document

1 / 79

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHP scripting language
CONTENTS
UNIT I
Introducing PHP Basic development Concepts Creating first PHP Scripts Using
Variable and Operators Storing Data in variable Understanding Data types Setting and
Checking variables Data types Using Constants Manipulating Variables with Operators.
UNIT II
Controlling Program Flow: Writing Simple Conditional Statements - Writing More Complex
Conditional Statements Repeating Action with Loops Working with String and Numeric
Functions.
UNIT III
Working with Arrays: Storing Data in Arrays Processing Arrays with Loops and Iterations
Using Arrays with Forms - Working with Array Functions Working with Dates and Times.
UNIT IV
Using Functions and Classes: Creating User-Defined Functions - Creating Classes Using
Advanced OOP Concepts. Working with Files and Directories: Reading Files-Writing Files-
Processing Directories.
UNIT V
Working with Database and SQL : Introducing Database and SQL- Using MySQL-Adding
and modifying Data-Handling Errors Using SQLite Extension and PDO Extension.
Introduction XMLSimple XML and DOM Extension.
BOOK FOR STUDY
―PHP A Beginner’s Guide ―, VIKRAM VASWANI, Tata McGraw-Hill
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f

Partial preview of the text

Download Web Technology for III BCA and more Study notes Web Application Development in PDF only on Docsity!

PHP scripting language CONTENTS UNIT – I Introducing PHP – Basic development Concepts – Creating first PHP Scripts – Using Variable and Operators – Storing Data in variable – Understanding Data types – Setting and Checking variables Data types – Using Constants – Manipulating Variables with Operators. UNIT – II Controlling Program Flow: Writing Simple Conditional Statements - Writing More Complex Conditional Statements – Repeating Action with Loops – Working with String and Numeric Functions. UNIT – III Working with Arrays: Storing Data in Arrays – Processing Arrays with Loops and Iterations – Using Arrays with Forms - Working with Array Functions – Working with Dates and Times. UNIT – IV Using Functions and Classes: Creating User-Defined Functions - Creating Classes – Using Advanced OOP Concepts. Working with Files and Directories: Reading Files-Writing Files- Processing Directories. UNIT – V Working with Database and SQL : Introducing Database and SQL- Using MySQL-Adding and modifying Data-Handling Errors – Using SQLite Extension and PDO Extension. Introduction XML—Simple XML and DOM Extension. BOOK FOR STUDY ―PHP A Beginner’s Guide ―, VIKRAM VASWANI, Tata McGraw-Hill

SENGUTHAR ARTS AND SCIENCE COLLEGE.

DEPARTMENT OF COMPUTER SCIENCE

Staff Name: M.CHINNUSAMY Class:III-BCA Paper Name: PHP scripting language Unit: I Unit-I History of PHP:  PHP was first developed by Rasmus Lerdorf.  PHP: Hypertext Preprocessor (or simply PHP) is a server-side scripting language designed for Web development, and also used as a general-purpose programming language. It was originally created by Rasmus Lerdorf in 1994.  PHP originally stood for Personal Home Page , but it now stands for the recursive initialize PHP: Hypertext Preprocessor.  PHP (recursive acronym for PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.  He created a set of CGI script to monitor page views for his online resumes.  The early version of PHP is PHP/FI. It supports for form Input and the mySQL database.  It has lack of security features.  Later it was improved and released has PHP/FI 2.0 in 1997.  Andi Gutmans and Zeev Suraski rewrote the PHP parser and released it as PHP 3.0.  PHP 3.0’s syntax more powerful and consistent.  PHP 4.0 was released in 2000. It offered a new engine, better performance and reliability and built- in support for sessions and object oriented features.  PHP 5.0 was released in 2004, was a radical redesign of PHP 4.0, a much improved object model and various security performance improvements.  PHP 5.0 also introduced various new and important tools:

  1. A common database access layer
  2. Java-style exception handling and
  3. An integrated database engine  PHP 5.3 is the most recent version was released in January 2008.  It improves the versions of PHP 5.  It supports:
  4. Name space
  5. Built in support for SQLite 3
  6. New native driver for MySQL  PHP 5.3 is the best PHP released in the language’s fourteen year history, a fact amply illustrated by the April 2008 Net craft survey, which shows PHP in use on over thirty million web sites.

The development environment must contain at least three components:

  1. A base operating system and server environment.
  2. A web server usually apache on Linux or IIS on windows to intercept HTTP requests and either serve them directly or pass them on the PHP interpreter for execution.
  3. A PHP interpreter to parse and execute PHP code, and return the results to the web server.
  4. Optional: The database engine such as MySQL that holds, application data accept connections from the PHP layer, and modifies or retrieves data from the database. Using Variables and Operators: Storing data in variables:  A variable is simply a container that’s used to store both numeric and non-numeric information. Assigning values to variables:  Assigning a value to a variable in PHP is quite easy: use the equality symbols, which also happens to be PHP’s assignment operator.  This assigns the value on the right side of the equation to the variable on the left. Ex: $name=’PHP’; $a=5; Ex:
**_Variables:_**  Every variable name must be preceded with dollar symbol and must begin with a letter or underscore character, optionally followed by more letters, number or underscore character.  Common punctuations, characters such as commas, quotation marks or provide are not permitted in variable name.

Ex: $root, $_num, $query2 Valid $58%, $1day, email Invalid Destroying Variables: To destroy a variable, pass the variable to PHP’s aptly named unset() function. Ex:

**_Inspecting Variables contents:_** PHP offers var_dump() function which accept a variable and x-rays it for you. Ex: **_Understanding PHP data types:_**  PHP supports data type like integer, float, and string, Boolean, null.  Boolean are the simplest of all PHP data types. Ex:

 PHP support more than 50 such operators for arithmetical operations, logical comparisons and bitwise calculations. Performing Arithmetic operators: PHP supports all standard arithmetic operations. Operator Description

  • Addition
  • Subtraction
  • Multiplication / Divide and return quotient % Divide and return modulus Ex:
**Concatenating Strings:** To combine strings, use PHP’s concatenation operator, which happens to be a period (.). Ex: **Comparing Variables:** PHP lets you compare one variable or value with another via its wide range of comparison operators. Ex: $p=10; $q=11; $r=11.3; $s=11; echo ($q>$p); echo ($q<$p); echo ($q>=$s); echo ($r<=$s); Operators Descriptions = = Equal to =! Not equal to

Greater than = Greater than or equal to < Less than <= Less than or equal to = = = Equal to and of the same type Ex:

(= = =) This operator allows for stricter comparison between variable: it only return true if the two variables or value being compared hold the same information and are of the same data type. **Performing Logical test:** PHP supports the logical operators. **Operator Description** && AND || OR ! NOT Ex: 50&&$size<25); echo ($price>150||$size>75);

 The following list illustrates PHP’s most important precedence rules.  Operators at the same level have equal precedence.

  1. ++ -- 2.!
    • / %
    • -.
  2. < <= > >=
  3. = = != = = = != =
  4. &&
  5. ||
  6. = += - = = /= .= %= &= |= ^= Ex: (((48)-2)/10) ((((32)-2)/10) with parenthesis ((30)/10) 3 4*8-2/ 32 - 0.8 without parenthesis

Handling form Input:

Select your car

Type:

Color:

Success!

********* END OF THE UNIT-I ********* **Unit-I Questions**
  1. write any 2 features of PHP.
  2. How to create a variable in PHP?.
  3. Explain how to assign values to variables in php.
  4. Write short notes on PHP development environment components.
  5. Explain in detail about comparison operators with examples.
  6. Write about PHP data types
  7. Explain the setting and checking variable data types in PHP.
  8. Explain the concept of Assigning, Destroying and Inspecting variables in details.
  9. Explain in detail about operators with examples.
  10. Write about string concatenation.

Example:

Here, an if – else statements is used to account for two possible outcomes: a number less than zero, and all other number. II. **WRITING MORE COMPLEX CONDITIONAL STATEMENTS** The if – else statement lets you define actions for two eventualities: a true condition and a false conduction. The if - elseif-else statement and the switch - case statements. **i) IF - ELSEIF-ELSE STATEMENT** The if - elseif-else statement lets you chain together multiple if – else statements, thus allowing the programmer to define actions for more than just two possible outcomes. Consider the following examples , which illustrates its use: Here, the program will output a different message for each day of the week (as set in the $today variable).

ii)SWITCH-CASE STATEMENT An alternative to the if-elseif-else statement is the switch-case statement, which does almost the same thing: it tests a variable against a series of values until it finds a match, and then executes the code corresponding to that match. Consider the following code listing, which is equivalent to the preceding one:

The switch-case construct differs from the if-elseif-else construct in one important way. Once PHP finds a case statement that evaluates to true, it executes not only the code corresponding to that case statement, but also the code for all subsequent case statements. If this is not what you want, add a break statement to the end of each case block (as is done in the previous listing) to tell PHP to break out of the switch-case statement block once it executes the code corresponding to the first true case. Notice also the ‘default’ case: as the name suggests, this specifies the default set of actions PHP should take if none of the other cases evaluate to true. This default case, like the else branch of the if-elseif-else block, is very useful as a “catch-all” handler for unforeseen situations. **iii) COMBINING CONDITIONAL STATEMENTS** PHP allows one conditional statement to be nested within another, to allow for more complex decision-making. To illustrate this, consider the following listing: // repeat continuously until counter become 10 // output : ‘XXXXXXXXXXX’ $counter = 1; While ($counter < 10) { echo ‘x’ ; $counter++; } ?> ii) DO-WHILE LOOP With a while loop, the condition to be evaluated is tested at the beginning of each loop iteration. There’s also a variant of this loop, the do-while loop, the do-while loop, which evaluates the condition at the end of each loop iteration.

**iii) FOR LOOP** The while and do-while loops are firely simple: they repeat for so long as the specified condition remains true. But PHP also supports a more sophisticated type of loop, the for loop, which is useful when you need to execute a set of statements a specific number of times. The best way to understand a for loop is by looking at some code. Here’s simple example, Which lists the numbers between 1 and 10.  The first of these is an assignment expression, which initialize the loop counter to a specific values in this case, assigning the value 1 to the variable $x.  The second is a conditional expression, which must evaluate to either true or false; the loop will continue to execute so long as this condition remains true. Once the condition becomes false, the loop will stop executing.

 The third is again an assignment expression, which is executed at the end of each loop iteration, and which updates the loop counter with a new value – in this case, adding 1 to the value of $x. iv)COMBINING LOOPS Just as with conditional statements, it’s also possible to nest one loop inside another. To illustrate, consider the next example, which nests one for loop inside another loop to dynamically generate an HTML table. Example:

”; for ($row =1 ; $row<4; $row++) { echo “”; for ($col =1; $col<5; $col++) { echo “Row $row, column $col< /td>”; } echo “”; } echo “”; ?> ”; for ($x=1; $x<7; $x++) { echo “
  • Item $x
  • ”; } echo “ ”; ?>

    i)USING STRING FUNCTIONS PHP has over 75 built-in-string manipulation functions, supporting operation ranging from string repetition and reversal to comparison and search- and – replace. Table 3-3 lists some of these functions. a) Checking for empty strings The empty( ) function returns true if a string variable is “empty”. Empty string variables are those with the values ‘ ‘ ,0, ‘0’, or NULL. The empty ( ) function also returns true when used with a non-existent variable. Here are some examples:

    **FUNCTION WHAT IT DOES** empty( ) Tests if a string is empty strlen( ) Calculates the number of character in a string strrev( ) Reverses a string str_repeat Repeats a string substr() Retrieves a section of a string strcmp() Compares two string str_word_count() Calculates the number of words in a string str_replace() Replaces parts of a string trim() Removes leading and trailing whitespace from a string strtolower() Lowercases a string strtoupper() Uppercases a string ucfirst() Uppercases the first character of a string ucword() Uppercases the first character of every word of string addslahes() Escapes special characters in a string with backslashes stripslashes() Remove backslashes from a string

    htmlentities() Encodes HTML within a string htmlspecialchars() Encodes special HTML characters within a string nl2br() Replaces line breaks in a string with
    elements html_entity_decode() Decodes HTML entities within a string htmlspecialchars_decode() Decodes special HTML characters within a string strip_tags() Removes PHP and HTML code from a string b) Reversing and Replacing Strings The strlen() function returns the number of characters in a string. Here’s an example of it in action:

    Reversing a string is as simple as calling the strrev() function, as in the next listing: In case you need to repeat a string, PHP offers the str_repeat() function, which accepts two arguments----the string to be repeated, and the number of times to repeat it. Here’s an example: **c) Working with Substrings** PHP also allows you to slice a string into smaller parts with the substr() function, which accepts three arguments: the original string, the position (offset) at which to start slicing, and the number of characters to return from the starting position. The following listing illustrates this in action: