PHP Scripting Essentials: From Basics to Advanced Concepts

Slide Note
Embed
Share

"Explore the comprehensive syllabus covering PHP scripting fundamentals, from variables and constants to decision-making statements, iterative loops, functions, and arrays. Understand the history of PHP, its evolution, and how it plays a crucial role in web development today."


Uploaded on Sep 28, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Unit I: Introduction to PHP Scripting Syllabus Content : Introduction: Evaluation, Features, PHP Script(PHP tags <?php... ?>, SGML-style tags<?...?>,ASP style <% ... %>, HTML Script Tag), Comment(single and multiline), echo command, PHP script execution on terminal and web browser. Variables: Basics, Data types(Boolean, Integers, Floating points Doubles, Strings, NULL, Arrays,Resources), Variable naming rules, scope(Local, Global, static, function parameter), unset variable,Functions(gettype(), isset(), is_array(), is_bool(), is_float(), is_int(), is_null(), is_string(),is_resource()) Constant: define() function to define constant, constant() to retrieve value of constant, difference between constant and variable, PHP predefined constants Operators: Arithmetic, Comparison, Relational, Assignment, Increment-Decrement, Ternary,Bitwise, Casting, Other operators(., $, @, {}, ``, =>),Operator Precedence Strings: Single Quoted and Double Quoted, escape sequences, Multiline String, Concatenationoperator(.), string functions(chr(), strlen(), ltrim(), rtrim(), trim(), strtoupper(), strtolower(),strcmp(), substr(), strrev(), echo(), print(), printf())

  2. Decision Making Statements: if, if... else, if ... elseif...else, switch statement Iterative Statements: for, while, do... while, foreach, break and continue statement Exit statements: exit, die User Defined Functions: Declaring functions, function arguments(byval, byref, default arguments,variable number of arguments),return statement(by val, by ref), recursion, global scope, staticvariables, Dynamic Function call Arrays: Concept, Types(Numerical/List, Associative/Maps, MultiDimentional), empty array,Initialisation of arrays([] operator, array() function, range() function), inserting element in array,Display entire array(print_r(), var_dump()), Sorting functions(sort(), rsort(), asort(), arsort(),ksort(), krsort(), natsort(), natcasesort(), array_multisort(), usort()), is_array() function, mergearrays(array_merge()) and using + operator, array as stack(array_push(), array_pop(),array_shift(),array_unshift()), reverse array(array_reverse()), array_keys() and array_value(), key().

  3. Introduction: Today s world is web based; numerous tasks are performed on the web. PHP is most accepted web development language in the globe because it is open source and easy to learn. PHP is server side scripting language and supports plenty of databases. PHP provides huge number of inbuilt functions as they can be used for several purposes such as array, strung manipulation, file handling, database handling, networking, graphics, security etc. Before commencing work of application development, developer must know software required and installation process. 1.1 History History tells number of things like the pioneer of technology, purpose of development, year of development, chronic and new name of technology etc. The concept of PHP was coined by Rasmus Lerdorf in the year 1995. Purpose of PHP development is to create dynamic web pages. PHP is the abbreviation of PHP Hypertext Preprocessor . Initially PHP was called as Personal Home Page .

  4. 1.2 What is PHP? PHP is a server side scripting language based on Zend engine. Before knowing more about PHP, it is very important to understand the difference between programming languages & scripting languages. The way of execution of programming language & scripting language is not same. Following are the key point which differentiates between programming and scripting language. i) Execution: Programming languages such as C++, Java and C#.NET are compiled. a) After compilation of C program .obj file is created. b) After compilation of C++ program .obj file is created. c) Java is programming language, which requires two steps for the execution. In first step java program is compiled and byte code is created and in second step it is interpreted. d) After compilation of C# program MSIL (Microsoft Intermediate Language) is created. Scripting language such as PHP, ASP, JavaScript and PERL are interpreted.

  5. ii) Speed: Speed of the execution of programming language is better than the speed of execution of scripting languages because in programming languages, compiled code is already converted into the machine language. As a result it will execute faster. Programming languages are categorized into procedure oriented, object oriented, pure object oriented etc. In the same manner scripting languages are divided into client side scripting and server side scripting

  6. Client side Scripting 1. JavaScript, VBScript are the client side scripting languages. 2. Execution of client side scripting takes place at client side (on local machine). 3. Client side scripting languages are executed by the web browsers. 4. Speed of execution of the client side scripting languages is faster because user s request is processed at the clients end. Hence user gets faster response. Server Side Scripting 1. PHP, ASP etc. are the server side scripting languages. 2. Execution of the server side scripting languages takes place at server side(on remote machine). 3. Server side scripting languages are executed by the web servers. 4. Speed of execution of the server side scripting languages is less compare to the client side scripting languages because user request is processed at the remote machine. Request travels through the network hence user get slower response.

  7. PHP is essentially used for web development: PHP is used for the developing dynamics web sites. PHP is used for the CMS (Content Management System) hence huge data can be uploaded on to the server. PHP is server side scripting language in which clients request is processed in following manner. i) Client sends request to the Server. ii) Server process the Client s request. iii) Server sends result to the Client.

  8. Following are the key terms related to the web development. Web browser: request to the server. Examples: Internet Explorer, Mozilla Firefox, Google Chrome etc. It is the software installed on client s machine. Web browser sends client Web Server: client s request. Examples: IIS(Internet Information Server), Apache etc. It is the software installed on server machine. It is responsible for processing Web Site: (Hypertext Markup Language), PHP, ASP etc. It consists of user information, Images, Video etc. Every website contains one main page that is called homepage of the website. It appears first when user access the website. Based on the services, cost of development and maintenance; web sites are categorized into the static web site & dynamic website. It is collection of the web pages. Web page is created by using HTML

  9. PHP is open source and free; it means PHP is free to use and can be duplicated and altered as per users requirement. Versions of PHP Every version of PHP has different features. Successor version of PHP contains all features of previous versions; in addition to that it contains new features also. Version information of PHP can be obtained by using phpinfo() function. The first PHP was launched in 1995. The latest version of PHP is PHP6.

  10. Why PHP? Following are the key points because of which programmers are being attracted towards the PHP. 1. PHP is platform independent hence PHP programs can run on any operating systems. 2. It is free and open source. 3. It supports many web servers such as IIS, Apache etc 4. PHP supports many web browsers such as Mozilla Firefox, Internet Explorer and and Google Chrome etc. 5. PHP supports many databases such as Microsoft Access, SQL Server, MySQL and Oracle etc. however PHP-Apache-MySQL is a good combination for the web development. 6. Many concepts and syntax of PHP are same as C language because of which PHP is easy to learn. 7. PHP code is embedded into the HTML to make the web pages dynamic.

  11. Installation of PHP Installing PHP on any operating system is very easy task. Three software s are required to execute PHP script on any operating system. i) PHP Engine: It runs the PHP scripts ii) Web Server: Web Server (IIS, Apache etc.) is required to process user s request. iii) Database: It is one of the way to store huge amount of data permanently. We can install each component separately or can get these three components together in package. There are four different packages provided by the PHP i) WAMP(Windows Apache MySQL PHP) ii) LAMP (Linux Apache MySQL PHP) iii) MAMP(Mac OS Apache MySQL PHP) iv) XAMPP(X-Cross Platform Apache MySQL PHP)

  12. Fundamentals of PHP Variable declaration in programming Here we can see the variable concept following point wise. What is Variable? Variable is name given to the memory location. The term Variable itself says it is not fixed; it can be changed. Every variable has associated data type and its value. Example int a=10; Why to declare variable? Computer memory is divided into the number of blocks. Each size of block is considered as one byte. Each block has unique address assigned by the operating system and name (variable name) given in the program. Declaration of variable tells to the compiler how many bytes of memory should be allocated to store the particular variable value. Example: int n;

  13. How to declare variable? Different languages have different syntax for declaring the variable specific number of bytes of memory. Even the syntax of variable declaration is different; purpose is to allocate

  14. Variable declaration in PHP Following are important points, while variable declaration. i) In PHP, variable name must start with dollar sign($) Example: $name,$a,$b etc. ii) First character must be understood or letter after the dollar sign. iii) Variable names are case sensitive. Example: $abc is not same as $ABC

  15. iv) Initialize the variable at the time of declaration Example: $Name= Sharad ; $Age=15; $Gender= M Another important thing in PHP for variable declaration is that there is no need to specify the data type for the variable. PHP automatically understands the data type of the variable by its initialization. In above example variable $Name has string data type, $Age has integer data type and $Gender has character data type.

  16. We can display the value of the variable by using echo statement. Script: <?php $a=20; echo Valueof A= , $a; ?> Output: Value of A=20

  17. Constants in PHP are two ways to declare the constant in PHP. Once the value of the constant is fixed, it cannot be changed later. There i) const keyword ii)define() function i) const keyword the dollar sign is not being used. Keyword const is used to declare the constant. While declaring constant,

  18. Constants in PHP ii) define() function PHP provides inbuilt function define() to declare the constant. Syntax: define( nameofconstant , value of constant); Script: <?php define( name ,40); echo name; ?> Output: 40

  19. Comments in PHP Comment is text, which is ignored by the PHP engine. Comments are used to explain the purpose of code. PHP supports two types of comments. i) Single line comment ii) Multiline comment i) Single line comment It is used to specify the comment for single line. It can be specified by two ways i) Backward slashes(//) ii) Hash(#) Script: <?php $a= NSS ; $b= c ; ?> //$a variable data type is string # $b variable data type is character

  20. Comments in PHP ii) Multiline Comment It can be used to specify block of statements. /* Line 1 Line 2 Line 3 */

  21. Data types in PHP PHP supports number of data types. Data type tells us about the type of value stored by the variable. Following are the categories of data type supported by the PHP. a) Single data types b) Mixed data types c) Special data types a) Single data types Single data type is also called as scalar data type. The meaning of scalar is single. The data type which stores single value is called as scalar data type. PHP has following scalar data types,

  22. Data types in PHP b) Mixed data types Mixed or Compound data type is a produce of the scalar data type and it can store multiple values. PHP have following compound data types.

  23. Data types in PHP c) Special data types PHP has following special data types

  24. Data types in PHP Type Checking programming. It is the task of compiler or interpreter to check, whether assigned value of the variable matches with the data type or not. The compiler, which checks strict match of data type and value, is called as strongly typed checking language. The compiler which does not checks strict match of data type and value is called as loosely typed checking language. PHP is loosely type checking language. Advantage of loosely type checking language is that the data type changes automatically according to value of the variable. The disadvantage of loosely type language is that sometimes data is lost. Advantage of strongly type checking language is to protect the value of variable. The disadvantage of strongly type checking language is, it requires providing value for the variable according to data type. Declaring proper data type for the variable is very important in

  25. PHP Tags When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: <?php // PHP code goes here ?> The default file extension for PHP files is ".php".

  26. PHP Tags A PHP file normally contains HTML tags, and some PHP scripting code. that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page: Below, we have an example of a simple PHP file, with a PHP script Example <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> PHP statements end with a semicolon (;).

  27. PHP Case Sensitivity In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive. In the example below, all three echo statements below are equal and legal: Example <!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html>

  28. PHP Case Sensitivity However; all variable names are case-sensitive! Look at the example below; only the first statement will display the value of the $color variable! This is because $color, $COLOR, and $coLOR are treated as three different variables: Example <!DOCTYPE html> <html> <body> <?php $color = "red"; echo "My car is " . $color . "<br>"; echo "My house is " . $COLOR . "<br>"; echo "My boat is " . $coLOR . "<br>"; ?> </body> </html>

  29. Combining PHP and HTML PHP syntax is applicable only within PHP tags. PHP can be embedded in HTML and placed anywhere in the document. When PHP is embedded in HTML documents and PHP parses this document it interpreted the section enclosed with an opening tag (<?php) and closing tag (?>) of PHP and ignore the rest parts of the document. PHP and HTML are seen together in the following example. <html> <head> <title> PHP Page</title> </head> <body> <?php echo "Hello World..."; echo "Hello World..."; ?> </body> </html>

More Related Content