140 likes | 265 Views
Best Way to Learn PHP with www.myassignmenthelp.net
E N D
PHP (Hypertext Preprocessor) www.myassignmenthelp.net
Overview of PHP • PHP stands for Hypertext Preprocessor • Created by Rasmus Lerdorf in 1995 • It is an open source software • It is server-side scripting language, like ASP and executed on the server • More functionality added (OOP features), database support, protocols and APIs • A language that combines elements of Perl, C, and Java • It is free to use and download • PHP files can contain text, HTML tags and scripts and file extension of ".php" or ".phtml“ • PHP files are returned to the browser as plain HTML www.myassignmenthelp.net
PHP Syntax • PHP code is executed on the server, and the plain HTML result is sent to the browser. • Syntax: It is starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document. • Comments in PHP • use // to make a single-line comment or /* and */ to make a large comment block. Www.myassignmenthelp.net
PHP Language Basics • Constants, Data Types and Variables • Constants define a string or numeric value • Constants do not begin with a dollar sign • Examples: • define(“COMPANY”, “Acme Enterprises” ); • define(“YELLOW”, “#FFFF00”); • define(“PI”, 3.14); • define(“NL”, “<br>\n”); • Data types • Integers, doubles and strings • isValid = true; // Boolean • 25 // Integer • 3.14 // Double • ‘Four’ // String • “Total value” // Another string
Variables • It is used to store information. • It is used for storing information, like text strings, numbers or arrays. • All variables in PHP start with a $ sign symbol. • The declaring a variable • String variable: • used to store and manipulate text • script assigns the text "Hello" to a string variable called $text: www.myassignmenthelp.net
Operators • Arithmetic Operators • + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus ), ++ (Increment), -- (Decrement) • Assignment Operators • =, +=, -=, *=, /=, .=, %= • Comparison Operators • ==, !=, <>, >, <, >=, <= • Logical Operators • && (and), || (or), ! (not) www.myassignmenthelp.net
Conditional Statements • if Statement • execute some code only if a specified condition is true • if...else Statement • execute some code if a condition is true and another code if the condition is false • if...elseif....else Statement • use this statement to select one of several blocks of code to be executed www.myassignmenthelp.net
Switch Statement • Conditional statements are used to perform different actions based on different conditions. Syntax: www.myassignmenthelp.net
Loops • while Loop • executes a block of code while a condition is true. • do...while Statement • always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true. www.myassignmenthelp.net
Loops (cont) • for Loop • The for loop is used when you know in advance how many times the script should run. • foreach Loop • The foreach loop is used to loop through arrays. www.myassignmenthelp.net
Form • One of the main features in PHP is the ability to take user input and generate subsequent pages on the input. In this page, we will introduce the mechanism by which data is passes in PHP. • Let's consider the following two files: • query.php • result.php www.myassignmenthelp.net
$_GET Function • The built-in $_GET function is used to collect values in a form with method="get". • When using method="get" in HTML forms, all variable names and values are displayed in the URL. • Information sent from a form with the GET method is visible to everyone and has limits on the amount of information to send. • When the user clicks the "Submit" button, the URL sent to the server could look something like this: www.myassignmenthelp.net
$_POST Function • The built-in $_POST function is used to collect values from a form sent with method="post". • Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send and the variables are not displayed in the URL and 8 Mb max size for the POST method, by default also can be changed by setting the post_max_size in the php.ini file. • Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. www.myassignmenthelp.net
Thank You www.myassignmenthelp.net