Introduction to PHP PHP(PHP Hypertext pre-processor) – Embedded Scripting Language
Two types of HTML • •
Static Dynamic
Two Types of Tags • •
Empty - doesn’t require a closing tag Container – requires closing tag
Attribute – option that affects or enhance ho the tags display its contents on the webpage. 1. name 2. value 3. sign
Rasmus Lerdorf – conceptualize the php in 1994
Features of PHP • • • • • •
Simplicity Portabilty Speed Open Source Extensive Database Support
Comments – use for greater readability // - single line comment # - single line comment /* - multiline comment
Variable – the basic building blocks of any programming languages, use to store values
• • • • •
All variable names should be pre preceeded by a dollar sign($) Variable name must begin with letter(A-Z) or underscore. It cant begin with a number No spaces Case sensitive Make a habbit of naming variable with sense of their own
Variable Naming Conventions 1. Camel Hump 2. Underscore echo() & print()– function use to print data to standard output device. Variable Types 1. Integer – whole numbers 2. Floating point – decimal points 3. Strings – character, combination of letters and numbers, symbols and spaces enclosed in past of single(‘ ‘) or double (“ “) quotation marks. 4. 4 Boolean – true or false 5. Objects – Special Type of variables 6. array – an indexed collection of data 7. Null – a variable that has no values. gettype() – used to findout what type a particular variable is. settype() – us to explicity mark a variable as numeric or string. Using Operators
= assignment operators
=== equal to and to the same type
+ addition
!== not equal and not same data type
- subtraction
<> or ! mpt eqia;
* multiplication
< less than
/ division
<= less than or equal
% modulo
> greater than
== identical/equal to
> = greater than or equal
. concatenation
GET method - sends all the gathered information along as part of the URL
POST method – method transmute the information invisible to the users. NOTE : with the get method, a limited amount of information can be passed. The get method sends the input to the head line of the script publicy. A page generated by a form that used the get methodcan be bookmarked but one based on POST.
ini_set() function – allows a script to temporarily override a setting in PHP is configuration. Error Reporting: error_reporting() – determine what errors. PHP reports on.
PHP Error Types Notice – non-fatal error that may or may not be indicative of a problem Example: Refering to a variable that has no value. Warning – non-fatal error that is not likely problematic Example: Passing the wrong type mo parameters to a function. Parse Error – fatal error caused by a syntactical mistake Example: Omission of semicolon or imbalance of quotation marks, braces or parenthesis. Error – a general fatal error Example: Memory allocation problem