lecture 01.pptx
Document Details
Uploaded by HelpfulLosAngeles
Omdurman Islamic University
2021
Tags
Full Transcript
Internet Technology 2 Lecture 01 intro to PHP By Mr. Badraldeen Hassan | Omdurman Islamic University Faculty of Computer Science &Information Technology [email protected] 2021 The mental map for websites development...
Internet Technology 2 Lecture 01 intro to PHP By Mr. Badraldeen Hassan | Omdurman Islamic University Faculty of Computer Science &Information Technology [email protected] 2021 The mental map for websites development Website Dynamic Website Static Website Fronten Backen d d Programmi ng DBMS Languages Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | 2 [email protected] “PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible, and pragmatic, PHP powers everything from your blog to the most popular web sites in the world.” —www.php.net Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] What You Should Already Know HTML CSS JavaScript Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP 5.5+, PHP 7+, and PHP.NET Today, PHP (Hypertext Preprocessor) is one of the most popular languages used for web application development. The language has evolved to allow the programmer to quickly develop well-formed error-free programs using both procedural and objected-oriented programming techniques. It provides the ability to use many preexisting libraries of code that either come with the basic installation or can be installed within the PHP environment. This gives you multiple ways to complete a particular task. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Procedural language A procedural programming language includes functions/methods that can be called from the main flow of the program. The flow of the program jumps to the function/method, executes the code within the module, and then returns to the next statement in the main flow of the program. Some Procedural languages include a main function/method that automatically is called when the program is executed. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Object-oriented language An object-oriented language uses classes and objects. Classes are similar to blue prints. A class describes what an object can contain, including properties/variables and functions/methods. An object is an instance of a class (like a building that has been created from a blueprint). Object-oriented languages provide polymorphism, encapsulation, and inheritance. Objects are naturally encapsulated by containing all related functions/methods and properties/variables within the object itself. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP is an open source language As such, each version of the language is created using input from the individuals who use it—the programmers themselves. This allows the language, over time, to evolve and float into the direction that is driven by the users. From its first release in 1995 as a Personal Home Page Tool (PHP) by Rasmus Lerdorf, the versions have been released on the Internet with forums to provide users the ability to make suggestions and even provide code changes and additions. Today www.php.net is the official PHP web site. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Open source language An open source programming language is developed by a community of interested parties. The community accepts input from fellow programmers for suggested upgrades and corrections. Several members of the community work together to present proposals and to make changes to the language. Open source languages are “free”. A non-open source language (such as Microsoft C#) is created and updated by a company or major organization. Non-open source languages are not usually “free”. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] The www.php.net The www.php.net home page provides information on each of the latest releases of the language. It also provides information on future releases, the features planned for those releases, and the planned release dates. In addition, other related PHP information can be found, including links and information to major PHP conferences. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] The download page as you might have guessed, provides the ability to gain easy access to the latest versions of the language. However, as you will note, only the language itself is provided. It is more common, and recommended, that the beginning user use a WAMP (Windows, Apache, MySQL, PHP); LAMP (Linux, Apache, MySQL, PHP); or MAMP (Mac, Apache, MySQL, PHP) package for initial installation. These packages (which we will look at later) allow for easy installation of multiple products at the same time. Otherwise, you have to run many separate installations, which can become complicated and error-prone if incompatible versions are installed. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] WAMP/LAMP/MAMP Open source (free) combinations, including Apache Web Server, MySQL, and PHP for a specific operating system (Windows, Linux, and Mac). These packages are open source. The combination of software is used for creating dynamic web sites and web applications. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with : The default file extension for PHP files is ".php". Note: PHP statements end with a semicolon (;). Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP Case Sensitivity In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive. However; all variable names are case-sensitive! Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP Comments A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: Let others understand your code Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP supports several ways of commenting: Syntax for single-line comments: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Syntax for multiple-line comments: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Using comments to leave out parts of the code: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP Variables Variables are "containers" for storing information. In PHP, a variable starts with the $ sign, followed by the name of the variable: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables) Remember that PHP variable names are case-sensitive! Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Output Variables The PHP echo statement is often used to output data to the screen. The following example will show how to output text and a variable: OIU | FCSIT | [email protected] PHP is a Loosely Typed Language PHP automatically associates a data type to the variable, depending on its value. Since the data types are not set in a strict sense, you can do things like adding a string to an integer without causing an error. In PHP 7, type declarations were added. This gives an option to specify the data type expected when declaring a function, and by enabling the strict requirement, it will throw a "Fatal Error" on a type mismatch. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP Variables Scope The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: 1. local 2. global 3. static Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Global and Local Scope A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function): Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly. Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] PHP The static Keyword Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. To do this, use the static keyword when you first declare the variable: Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] To Be Continue Internet Technology II | By Mr. Badraldeen Hassan | OIU | FCSIT | [email protected] Notice This Course is available on my YouTube channel as video recorded https://www.youtube.com/c/BadraldeenHassanAlta hir Also available on my official Facebook account https://www.facebook.com/Badraldeen.Hassan