PHP scripting basics

Description

some basic notes on PHP scripting for web development.

Reviews
Shared by: Don Joseph Medrana
Stats
views:
2796
rating:
not rated
reviews:
0
posted:
9/9/2008
language:
pages:
0
INTRODUCTION TO PHP ____________________________________________________________________________________________ PHP Notes I. Introduction A. What is PHP? PHP, which stands for Php: Hypertext Preprocessor is a widely-used Open Source general-purpose language that is especially suited for Web development. As a server-side scripting language, PHP script is run on the web server, not on the client’s / user's browser. B. Why PHP? Learning a scripting language, or even understanding one, can open up new possibilities for your website. Using scripts empowers your web page and its users by allowing both to interact with each other. Feedback forms, guest books, message boards, counters and online databases are just some of the interactive features that scripts can provide. And what’s a better way to learn scripting than PHP. It's an easy-to-learn language yet very powerful, which is why it is quickly becoming one of the most popular scripting languages on the Internet. C. What can PHP do? PHP can: Manipulate databases Perform search engine functions Handle form data Handle e-commerce transactions Send / receive cookies Create client-side applications II. Getting Started A. What do I need to program in PHP? A Text Editor – Your text editor need not be a fancy one. MS Notepad can already serve the purpose. Avoid using MS Word or any other word processing program since these are not very well suited for scripting. A PHP engine – Since PHP is a server side scripting language, it has to be installed in your server / host. For the purpose of developing locally, a PHP engine has to be installed on a local computer. A Web Server – If you have access to a hosting account with PHP support, you are ready to write and upload your dynamic pages. Otherwise, if you have no access to a web host, you can install your own server on a local computer. B. Familiarizing with the Basic Syntax The most common ways to denote a PHP code are: Starts with - commonly used tags Starts with commonly used tags Starts with - simplest Starts with <% and ends with the %> - this is ASP style tag In PHP, instructions are separated / terminated with a semi-colon. To insert comments within the script, use // to make a one-line comment /* and */ to enclose a multi-line comment 1 INTRODUCTION TO PHP ____________________________________________________________________________________________ III. Data Types PHP supports the following data types: Boolean - expresses a truth value. It can be either TRUE or FALSE / YES or NO / 1 or 0 Integer - number of the set Z = {..., -2, -1, 0, 1, 2, ...}. Float - AKA "floats", "doubles" or "real numbers" String - series of characters Array - a variable containing multiple values, on an indexed basis Object – objects are simply references that are defined by classes IV. Variables Variables in PHP are represented by a dollar sign followed by the name of the variable (e.g., $variable1, $myvariable, $name, $VALUE, $ValUE, etc.). The variable name is casesensitive, which means the variable $Value is not the same as the variable $value. V. Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value (so that the construction itself becomes an expression). The table below enumerates some of the most commonly used operators: ARITHMETIC OPERATORS + * / Addition Subtraction Multiplication Division INCREMENTING / DECREMENTING OPERATORS Increments $a by 1 then returns $a Returns $a, then increments $a by 1 Decrements $a by 1 then returns $a Returns $a, then decrements $a by 1 == != < > <= >= COMPARISON OPERATORS Equal Not equal Less than Greater than less than or equal to greater than or equal to LOGICAL OPERATORS ! && || not And Or ++$a $a++ --$a $a-- VI. Control Structures A. Condition: the IF Statement The IF statement allows for conditional execution of code fragments. The syntax for the IF statement is as follows: B. Loops: the WHILE Statement The While statement tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The syntax for the IF statement is as follows: 2 INTRODUCTION TO PHP ____________________________________________________________________________________________ VII. Arrays An array maps values to keys. The script below illustrates how array is used: value, key => value); statement ?> While the previous expression is the quicker way to create and array, the following example ay also be used: According to convention, an array should start at index 0. It would be better if programmers would stick to conventions because it makes the codes readable to other programmers. VIII. Functions A function is a reusable code-block that will be executed when the function is called or triggered by a certain event. While PHP has both built-in functions, it also supports userdefined functions. The example below illustrates how array is used: IX. Dealing with Forms Setting up a form for use with a PHP script is exactly the same as normal in HTML. The important thing to remember is that the form should always be bound to a script that processes instructions on how to handle the form data. To do this, several methods can be used: POST method – most commonly use method of posting form data, as it is the more current and standard implementation. GET method – this method takes all the values entered in the form and tacks them on after the URL. A question mark is added to the end of the URL, followed by name=value pairs 3

Related docs
Basics of Php
Views: 57  |  Downloads: 2
PHP
Views: 1167  |  Downloads: 151
Introduction to PHP
Views: 90  |  Downloads: 14
Introduction to PHP
Views: 176  |  Downloads: 28
Programming PHP
Views: 6  |  Downloads: 1
learn php
Views: 8121  |  Downloads: 44
php analogy
Views: 207  |  Downloads: 7
PHP and Mysql
Views: 540  |  Downloads: 18
Introduction to HTML PHP
Views: 5  |  Downloads: 1
Intro to PHP
Views: 77  |  Downloads: 12
premium docs
Other docs by Don Joseph Med...
Donor Activity Philipines and Cambodia
Views: 167  |  Downloads: 1
service contract agreement for web hosting
Views: 788  |  Downloads: 108
Project Proposal Preparation -Development Projects
Views: 937  |  Downloads: 144
Web Development Project - Price Quote
Views: 1631  |  Downloads: 194
Transformation of Governance Paradigms
Views: 161  |  Downloads: 17
Project Cycle
Views: 273  |  Downloads: 69
163 - Trekking pathways to good governance
Views: 303  |  Downloads: 12