







































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 79
This page cannot be seen from the preview
Don't miss anything!
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
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:
The development environment must contain at least three components:
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
(= = =) 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);Greater than = Greater than or equal to < Less than <= Less than or equal to = = = Equal to and of the same type Ex:
The following list illustrates PHP’s most important precedence rules. Operators at the same level have equal precedence.
Handling form Input:
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:
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 stringhtmlentities() 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: