Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.

Slides:



Advertisements
Similar presentations
Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
PHP: Introduction By Trevor Adams.
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
PHP : Hypertext Preprocessor
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Copyright © Curt Hill PhP History and Introduction.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
INTERNET APPLICATION DEVELOPMENT For More visit:
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nael Alian Introduction to PHP
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
1 PHP Introduction Chapter 1. Syntax and language constructs.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Strings, output, quotes and comments
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP: The Basics.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Session 2 Basics of PHP.
Web Database Programming Using PHP
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Introduction.
PHP.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Lecture 5: Functions and Parameters
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
23 PHP.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special markup that indicates you are about to start using PHP looks like this: <?php … At the end of your PHP, use the closing markup: ?>

Variables and ConstantstMyn2 In the classroom PCs the configuration has been implemented so that each PC does have a Web server software (Apache HTTP Server) of it’s own. All the PHP files must be saved to the directory C:\Program Files\Apache Group\Apache2\htdocs\YourPersonalFoulderName This means that will display the home page of the local web site. Let’s test the first PHP page. Make sure the web server is running (it should always be running by default)

Variables and ConstantstMyn3

Variables and ConstantstMyn4

Variables and ConstantstMyn5 From the previous example we saw that you can intersperse your PHP code with HTML. So the HTML will be displayed by your browser, and the PHP will be run on your server – and if that PHP generates some HTML, that HTML will be displayed in your browser as well. You can insert PHP anywhere in your HTML page and the PHP engine on the web server will run it, as long as it is contained in the markup. When that PHP is run, any HTML it generates will be inserted into the page at the location of that PHP.

Variables and ConstantstMyn6 We used echo to display text using double quotes. Even if we could call echo as being a function, technically speaking echo is built-in PHP language construction. PHP statement ends with a semicolon. Never forget that when you work with PHP online, you are interacting with the user through a browser. That means that the text you send back to the browser will be interpreted as HTML, not just simple text. That also gives you the chance to make use of HTML to format your text:

Variables and ConstantstMyn7

Variables and ConstantstMyn8

Variables and ConstantstMyn9 You can also separate the items you want to print with commas:

Variables and ConstantstMyn10

Variables and ConstantstMyn11

Variables and ConstantstMyn12 You can also assemble text strings together into one string using a dot. In that case, PHP takes your expression and assembles it together (concatenation) into one single string:

Variables and ConstantstMyn13

Variables and ConstantstMyn14

Variables and ConstantstMyn15 There are three types of comments in PHP. The first type of comment lets you create multiline comments, which start with /* and ends with */. Single-line comment starts with // or # :

Variables and ConstantstMyn16

Variables and ConstantstMyn17

Variables and ConstantstMyn18 Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*‘. By default, variables are always assigned by value. That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other.

Variables and ConstantstMyn19 PHP also offers another way to assign values to variables: assign by reference. This means that the new variable simply references (in other words, "becomes an alias for" or "points to") the original variable. Changes to the new variable affect the original, and vice versa. To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable).

Variables and ConstantstMyn20

Variables and ConstantstMyn21

Variables and ConstantstMyn22 It is not necessary to initialize variables in PHP however it is a very good practice. Uninitialized variables have a default value of their type depending on the context in which they are used - booleans default to FALSE, integers and floats default to zero, strings (e.g. used in echo()) are set as an empty string and arrays become to an empty array.

Variables and ConstantstMyn23 PHP provides a large number of predefined variables to all scripts. The variables represent everything from external variables to built-in environment variables, last error messages to last retrieved headers. Some examples: $_GET An associative array of variables passed to the current script via the URL parameters. $_POST An associative array of variables passed to the current script via the HTTP POST method. $_SESSION An associative array containing session variables available to the current script.

Variables and ConstantstMyn24 PHP does not require that you create different types of variables for different types of data:

Variables and ConstantstMyn25

Variables and ConstantstMyn26

Variables and ConstantstMyn27 There is a shortcut way of displaying the values of the variables in the previous example, called string interpolation. When you use interpolation, you only have to place the variable whose value you want to insert inside a double- quoted text string (not single-quoted!!):

Variables and ConstantstMyn28

Variables and ConstantstMyn29

Variables and ConstantstMyn30 Sometimes, you don’t want a data item to be a variable. For example, the value of pi shouldn’t change. The thing to do here is to create a constant, whose value can’t be modified. You create a constant in PHP with the define function:

Variables and ConstantstMyn31

Variables and ConstantstMyn32

Variables and ConstantstMyn33 The define() function defines a constant. Constants are much like variables, except for the following differences:  A constant's value cannot be changed after it is set  Constant names do not need a leading dollar sign ($)  Constants can be accessed regardless of scope  Constant values can only be strings and numbers Syntax define(name,value,case_insensitive) ParameterDescription nameRequired. Specifies the name of the constant valueRequired. Specifies the value of the constant case_insensitiveOptional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant will be case-insensitive. Default is FALSE (case-sensitive)

Variables and ConstantstMyn34 PHP does you a big favor (?) by letting you store data without having to specify the data’s type. Sometimes, however, you have to know about the internal data types that PHP uses, such as: –boolean: Holds true/false values –integer: Holds numbers like -1, 0, 5 and so on –float: Holds floating-point numbers like , –string: Holds text like “PHP should be fun!” –array: Holds arrays of data items

Variables and ConstantstMyn35 Let’s do some tests. In the beginning there is a variable which is set to “0”. So even if it seems to be an integer number zero, it is actually a string “0”. What happens, if we try to add integer value 1 to that variable’s value?:

Variables and ConstantstMyn36

Variables and ConstantstMyn37

Variables and ConstantstMyn38 In this case, PHP does the best it can: adding the integer value 1 to the string “0” leaves $stringVariable holding the integer 1. What if you add a floating point value to the string “0”?:

Variables and ConstantstMyn39

Variables and ConstantstMyn40

Variables and ConstantstMyn41 Let’s still try to confuse PHP:

Variables and ConstantstMyn42

Variables and ConstantstMyn43