PHP Basics

Standard Tags <?php   ... code  ?>
Short Tags <?... code    ?>
<?= $variable ?>which allows you to print the result of an expression directly
to the script’s output.
Script Tags <script language=“php”>... code</script>
ASP Tags <%... code%>//deprecated

TO PRINT:   echo    printf,     sprintf, print_r, var_dump()
NOTE:echo is not a function and, as such, it does not have
a return value.
Difference between print and echo
print"String 1", "String 2";//Language Construct

if ((print "foo") && (print "bar"))

comments in php  //    # /*                                                   

* API Documentation Example
* @param string $bar
function foo($bar) { }

$x=pow(2,32);//4294967296 signed number proof system is 64 bit
$x=pow(2,64);//1.844674407371E+19 Not Handled by int4byte

echo $x;

VARIABLE VARIABLE   (isset,unset)

echo isset($x);//False

Special use of  curly Braces
$name="1ashish";//1ashish becomes variable but variable cannot start vith number
echo ${'1ashish'};//To resolve problem, we have to use { }

Note:Variable variables are a very powerful tool, and should be used with extreme care, not
only because they can make your code difficult to understand and document, but also
because their improper use can lead to some significant security issues.

 superglobal variables  $n= urldecode($_SERVER['QUERY_STRING']);


Typecasting:  settype($a,’string’’), gettype(),

intval(),   (int)$value,

$x=  ((0.1+0.7)*10);
echo $x;//8
$x=  (int)((0.1+0.7)*10);//7.9999999
echo $x;//7


ESCAPE SEQUENCE:\n   \r \$ \” \\ \t  \{ \[


Avoiding the need to escape quotes with heredoc syntax
form in html :get, post, request,

echo $left>$right;//True

echo $left<$right;//False

echo $left>$right;//1

echo (int)($left>$right);//1


echo ~$x;//-1
echo ~$x;//-2


• Assignment Operators for assigning data to variables
• Arithmetic Operators for performing basic math functions

echo $res;//0

• String Operators for joining two or more strings
  • Shift operator

echo $x;//2

echo $x;//1
echo $x;//1

• Comparison Operators for comparing two pieces of data
• Logical Operators for performing logical operations on Boolean values
In addition, PHP also provides:
• Bitwise Operators for manipulating bits using boolean math
• Error Control Operators for suppressing errors
@mysql_connect();//will not show any error like mysql_connect deprecated etc.
• Execution Operators for executing system commands
   backtick operator

$a = ‘ls -l‘;//Linux
echo `dir`;//Windows

• Incrementing/Decrementing Operators for incrementing and decrementing
echo $x;  //aashish
echo ++$x;//aashishi
echo ++$x;//aashishj

echo $x;  //aashish
echo --$x;//aashish
echo --$x;//aashish


numerical values
• Type Operators for identifying Objects

concat(.),comma(,);   increment decrement (++,--)    $fare Type = $age > 16 ? 'adult' : 'child';

type-juggling  (Handle with care)

if($str1==123){//PHP silently convert string to integer first
   echo "Hello";//Hello
if($str1===123){//=== is solution
   echo "Bye";//Nothing


start basic of html forms[htmlentities|striptags()]



Post a Comment