Powered By Blogger

Monday, 10 January 2011

Variable variables

Variable variables enable you to change the name of your variable dynamically
 For e.g.:
A=10;
$b=’A’
Now you can refer the value of the variable A with the $$b
As well as you can change the value indirectly
$$b= 15;
Will change the value of variable A to 15

Friday, 7 January 2011

String concatenation


To concatenate 2 or more word or sentences   in PHP we use the dot (.) operatorThis may help us when we need to form a string using values from different fields.
Example
string3= string1. String2

Difference between double and single quotes while being used with echo & heredoc syntax
While you are using double quotes with echo with a variable in between the quotes then the output will be the value of that variable.
But if you use the single quotes instead of double quotes then only the field (variable in between the quotes will be displayed not the value)

heredoc syntax:
echo<<<begin
line1
line2
line3
begin

 It keeps the order of lines and their positions unaltered.

Accessing form variables


Extraction of the values entered by the end user on the web form depends all upon the php version being used and php.ini configuration file.
Depending upon your PHP version and setup we can access each form field data via variables in three different ways
                                     1. $fieldname                             (security issue)
                                     2.$_POST[‘fieldname’]              (recommended)
                                     3.$HTTP_POST_VARS[‘fieldname’] ( can be disabled by register_long_arrays configuration directive which in results improves performance)

Data types

PHP is a loosely or dynamically typed language which means you do not need to explicitly declare the data type of the variable……interpreter sets the value type depending upon the value stored to the variable…..Types of values those can be stored in Php are
Integer
String
Float
Array
Object
Boolean
Although casting(conversion fron one datatype to another) is not necessary in php but can be performed just in the same way as it was in c
Var2 = (data type) var1

Embedding Php in html:

Php provides the flexibility to use different style of opening and closing tags....... anything in between these tags gets interpreted by the interpreter at the server end……
1.     XML STYLE:
<?php   ………………….    >
2.     SHORT STYLE :
                             <? ………………. >

3.     SCRIPT STYLE
                            <script language=’php’>………………..</script>

4.     ASP STYLE
<% ……………………………………….%>
Here “asp_tags” settings should be enabled.