Web2 PDF - Web Tech
Document Details
Uploaded by MesmerizingSeaborgium
Modern College
Tags
Related
- Unit 1. Web programming platforms in server environment. Characteristics of the PHP language V8.pdf
- Unit 1. Web programming platforms in server environment. Characteristics of the PHP language V8.pdf
- BCA Web Technology Exam November 2022 PDF
- Introduction to PHP Practical 1 PDF
- Web Technologies-II PDF
- Web Technology Assignment 4 PDF
Summary
This document is a document about web technology, which is focused on explaining the basics of PHP, and shows some examples and syntax about creating variables and using statements.
Full Transcript
Unit 2 Web Tech Cont…… ► 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 be used t...
Unit 2 Web Tech Cont…… ► 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 be used to control user-access ► PHP can encrypt data What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code is executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php" Note: ► Unlike other programming languages, PHP has no command for declaring a variable. ► It is created the moment you first assign a value to it. PHP $ and $$ Variables ► The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. ► The $$var (double dollar) is a reference variable that stores the value of the $variable inside it. Get the type: The var_dump() function returns the data type and the value: var_dump(5); var_dump("John"); var_dump(3.14); var_dump(true); var_dump([2, 3, 56]); var_dump(NULL); Syntax: To create a constant, use the define() function. define(name, value, case-insensitive); Ex: define("GREETING", "Welcome to PHP!"); function myTest() { echo GREETING; } myTest(); Constants are Global You can also create a constant by using the const keyword. const MYCAR = "Volvo"; echo MYCAR; Keywords: PHP String $x = "Hello world!"; $y = 'Hello world!'; var_dump($x); echo ""; var_dump($y); PHP Integer $x = 5985; var_dump($x); PHP Float $x = 10.365; var_dump($x); PHP Boolean $x = true; var_dump($x); PHP Array $cars = array("Volvo","BMW","Toyota"); var_dump($cars); PHP NULL Value $x = "Hello world!"; $x = null; var_dump($x); Global Scope ► A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function: $x = 5; // global scope function myTest() { // using x inside this function will generate an error echo "Variable x inside function is: $x"; } myTest(); echo "Variable x outside function is: $x"; Local Scope function myTest() { $x = 5; // local scope echo "Variable x inside function is: $x"; } myTest(); // using x outside the function will generate an error echo "Variable x outside function is: $x"; ► EX: If ► if (5 > 3) ► { echo "Have a good day!"; } Ex. If else $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } Switch Statments ► switch(n) ► ( case statements: code to be executed ► if n==statementi; break; case statements: code to be executed ► if n==statementz; break; ► case statement3: code to be executed ► if n--statement3; break; ► case statement4: code to be executed n==statement ► if break; 4: ►...... default: cOde to be executed if n != any case; Super globals variables ►These are variables that are automatically available ►throughout all program code,in all scopes. ►No declaration is required. ►$_GET ►$_POST ►$_SERVER ►$_REQUEST ►$_GLOBALS $_GET ► $_GET contains an array of variables received via the HTTP GET method. ► There are two main ways to send variables via the HTTP GET method: ► Query strings in the URL ► HTML Forms-In the action file we can use the $_GET variable to collect the value of the input fields.