1. Trang chủ
  2. » Luận Văn - Báo Cáo

Lecture E-Commerce - Chapter 29: PHP (part I)

66 40 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 66
Dung lượng 373,32 KB

Nội dung

After studying this chapter you will be able to understand: PHP comparison operators, PHP conditional statements, PHP - The if...else statement, the PHP switch statement, the PHP while loop, the PHP foreach loop,...

CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad Virtual Campus, CIIT COMSATS Institute of Information Technology T2-Lecture-09 PHP Part-I T2-Lecture-09 For Lecture Material/Slides Thanks to: www.w3schools.com What You Should Already Know  Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-3 What is PHP?  PHP is an acronym for "PHP Hypertext Preprocessor"  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP costs nothing, it is free to download and use T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-4 What is a PHP File?  PHP files can contain text, HTML, CSS, JavaScript, and PHP code  PHP code are executed on the server, and the result is returned to the browser as plain HTML  PHP files have extension ".php" T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-5 What Can PHP Do?  PHP can generate dynamic page content  PHP can create, open, read, write, delete, and close files on the server  PHP can collect form data  PHP can send and receive cookies  PHP can add, delete, modify data in your database  PHP can restrict users to access some pages on your website  PHP can encrypt data  With PHP you are not limited to output HTML You can output images, PDF files, and even Flash movies You can also output any text, such as XHTML and XML T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-6 Why PHP?  PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP supports a wide range of databases  PHP is free Download it from the official PHP resource: www.php.net  PHP is easy to learn and runs efficiently on the server side T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-7 What Do I Need?  To start using PHP, you can:  Find a web host with PHP and MySQL support  Install a web server on your own PC, and then install PHP and MySQL T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-8 Use a Web Host With PHP Support  If your server has activated support for PHP you not need to anything  Just create some php files, place them in your web directory, and the server will automatically parse them for you  You not need to compile anything or install any extra tools  Because PHP is free, most web hosts offer PHP support T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-9 Set Up PHP on Your Own PC  However, if your server does not support PHP, you must:  install a web server  install PHP  install a database, such as MySQL  The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 110 The PHP strpos() function  The strpos() function is used to search for a specified character or text within a string  If a match is found, it will return the character position of the first match If no match is found, it will return FALSE  The example below searches for the text "world" in the string "Hello world!":  Example  T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 152 The PHP strpos() function  The output of the code above will be:  Tip: The position of the string "world" in the example above is The reason that it is (and not 7), is that the first character position in the string is 0, and not T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 153 PHP Constants  A constant is an identifier (name) for a simple value The value cannot be changed during the script  A valid constant name starts with a letter or underscore (no $ sign before the constant name)  Note: Unlike variables, constants are automatically global across the entire script T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 154 Set a PHP Constant  To set a constant, use the define() function - it takes three parameters: The first parameter defines the name of the constant, the second parameter defines the value of the constant, and the optional third parameter specifies whether the constant name should be case-insensitive Default is false  The example below creates a case-sensitive constant, with the value of "Welcome to W3Schools.com!":  Example  Ahmed Mumtaz Mustehsan www.w3schools.com 155 Set a PHP Constant  The example below creates a case-insensitive constant, with the value of "Welcome to W3Schools.com!":  Example  T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 156 PHP Arithmetic Operators Operator Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % T2-Lecture-9 Modulus Ahmed Mumtaz Mustehsan $x % $y Remainder of $x divided by www.w3schools.com $y 157 Example  The example below shows the different results of using the different arithmetic operators:  T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 158 PHP Assignment Operators  The PHP assignment operators is used to write a value to a variable  The basic assignment operator in PHP is "=" It means that the left operand gets set to the value of the assignment expression on the right T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 159 PHP Assignment Operators Assignment Same as Description x=y x=y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x=x-y Subtraction x *= y x=x*y Multiplication x /= y x=x/y Division x %= y T2-Lecture-9 x = x % y Modulus Ahmed Mumtaz Mustehsan www.w3schools.com 160 Example  The example below shows the different results of using the different assignment operators:  T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 163 PHP Increment / Decrement Operators Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one $x Pre-decrement Decrements $x by one, then returns $x $x Postdecrement Returns $x, then decrements $x by one T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 164 Example  The example below shows the different results of using the different increment/decrement operators:  T2-Lecture-9 Ahmed Mumtaz Mustehsan www.w3schools.com 165 The End PHP Part-I Thank You T2-Lecture-9 Mustehsan Ahmed Mumtaz www.w3schools.com 166 ... JavaScript T2 -Lecture- 9 Ahmed Mumtaz Mustehsan www.w3schools.com 1-3 What is PHP?  PHP is an acronym for "PHP Hypertext Preprocessor"  PHP is a widely-used, open source scripting language  PHP scripts... < ?php and ends with ?>: ◦< ?php // PHP code goes here ?>  The default file extension for PHP files is " .php"  A PHP file normally contains HTML tags, and some PHP scripting code T2 -Lecture- 9... server  install PHP  install a database, such as MySQL  The official PHP website (PHP. net) has installation instructions for PHP: http:/ /php. net/manual/en/install .php T2 -Lecture- 9 Ahmed Mumtaz

Ngày đăng: 18/01/2020, 18:27