Tag Archives: Business – Oriented Solutions

PHP Compound Data Type

PHP consist of two compound types, arrays and objects.

Arrays

Arrays are special types of variables that can store more than one value. Arrays are useful when you need to store related variables data under one variable name.

An array can be declare in fallowing way:

$arr-name [key]= value;

In the above statement
arr_name is the name of the array.
Key is any string or a non negative integer. if you want to modify an array, it is best not to specify a key and to leave the square bracket empty.
Value is the data that is held in the array.

To understand the concept arrays, consider the fallowing codes:

<?php
$arr_name[0]="My";
$arr_name[1]="name";
$arr_name[2]="is";
$arr_name[3]="Rishi";
echo "$arr_name[0] $arr_name[1] $arr_name[2] $arr_name[3] $arr_name[4]";
?>

Output of the above code is: My name is Rishi

Objects

Objects are are the building blocks of a programming language . An object is an entity that can hold data and specify what need to be done with the data. Most of the internal working of an object are hidden from the code that uses them. Objects are a bundle of variable and functions that are derived from a class. To understand the concept of object you should be familiar with the fallowing terminology

Object orientation

The programming concept that revolves around objects.An object is an instance of a class.

Class.

A class is an entity that exibit certain behavior and expose certain attributes to retain state.

Properties

The character of an object defined by the class to which it belongs.

Methods

Task that can be performed by object on the data they contain.

Juggling Data Types

PHP does not require the developer to absolutely specify a data type for a variable at the time ofdeclaration. In PHP you need not worry about data type mismatches in an expression. Consider the fallowing example:

<?php
 $myVal = 7+ "2 is my number";
 echo $myVal;
?>

The output will be: 9.

In most other language ,the preceding code will not be valid. In PHP this statement is valid, and it also generates the expected output. This is because in PHP a variable doesn’t have fixed data type assign to it and can store any data type. The result of an expression is calculated on the basic of the operator and not on the basic of the operands. Examine the fallowing code for a better understanding of juggling data type:

<?php
  $a = "Rishi";
  $a +=2; // The += operator is use to add the initial value assigned to
// the variable to the number specified.r>  echo?>

The output will be : 2

In the above example ,$a contains a value that is of the string data type. In the next line, the += operator changes the initial variable assigned to $a to 2.

Consider another example where the .= operator is used to concatenate string:

<?php
 $a = "Rishi";r>  $a .=2; //The .= operator is use to concatenate two string .
 echo $a; //The value of $a is now Rishi2 
?>

The output will be: Rishi2

The . = operator tells the PHP that the number 2 is a string even though it is not specified in single quotes or double quotes. As a result it concatenates the initial value with the new value of $a, and the output is Rishi2.

Constants

A constant is a name that identifies a simple value. By nature, a constant is the opposite of a variable because the value of a constant remains fixed and doesn’t change when the script is executed. Constant have the fallowing characteristics:
– A constant is case sensitive by default.
– By convention, constant are expressed in uppercase letters.
– A consent can begin with either an underscore or with a letter, fallowed by any number of underscore, letters or numbers.

There are several other differences between variable and constants:

– A constant name never begins with a dollar sign .
– After a constant is set, it is not possible to to redefine or undefined it.
– A constant can contain only scalar data type like : Boolean, integer, float and string.
– A constant can be accessed and use anywhere in a script regardless of variable scoping rules.

Defining constants

A simple way to define a constant by using the define ( ) function. After you define a constant, you can read it’s value anytime you want by simply using it’s name. To read a constant value you can use the constant ( ) function. To obtained a list of all defined coinstants, you can use the get-defined-constants function.
In the fallowing code, a constant ADMIN_MAIL is defined with the value “contatc@a2zwebhelp.com”. Notice that constants are case sensitive, and the value assigned to the constant ADMIN_MAIL doesn’t appear when you try to print the value of the constant admin_mail:

<?php
    define ("ADMIN_MAIL" ,"contatc@a2zwebhelp.com");
  echo MIN_MAIL;
?>

The output will be: contatc@a2zwebhelp.com

PHP Variables

Introducing Variables

What is Variable?

Variables are known to hold data that can change during runtime of a program. The following are few important factor about PHP variables
– A PHP variable should declared using a dollar sign followed by variable name.
– A variable name can start with an underscore or with a letter.

– PHP variables are case sensitive .So, $Web  is not the same as $web.

Naming convention

Similar to other programming language such as C and C++, PHP also fallows a naming convention that should be used while declaring variables. Consider the fallowing example

$myVal = "My First Variable";

The above examples shows the naming convention used in PHP to declare a variable:
– The dollar sign: In PHP, each variable that you declared should begin with a dollar sign.
– Variable name: It is always advisable to choose meaningful variable names. Which will helpdevelopers to understand why the variable was declared and where it can be used. For example, if you use the variable name $u for User name and $e for User email address then  you may misinterpret it at a latter stage. So, when you start using PHP or any other programming languages  you should use meaningful variable names.
– Operator : The equal sign is an operator that assigns a value to the variables.
– Data type (value assigned to a variable):  The string “My First Variable” is the value that assign to the variable $myVal.

Variables are assigned using values. These value can be of Boolean, integer, float, or string type. Oncedeclared, variables can be referenced in a script.

HTML Special Characters

The table display the list of HTML Special Characters with Number and Name. Though in different character set the special characters looks like box or different shapes it is a best practices to use number or name in place of special characters.

Character Entity Number Entity Name
&#34; &quot;
&#39; &apos;
& &#38; &amp;
< &#60; &lt;
> &#62; &gt;
¡ &#161; &iexcl;
© &#169; &copy;
® &#174; &reg;
&trade; &#153;
« &#171; &laquo;
» &#187; &raquo;
° &#176; &deg;
± &#177; &plusmn;
&#182; &para;
¼ &#188; &frac14;
½ &#189; &frac12;
¾ &#190; &frac34;
× &#215; &times;
÷ &#247; &divide;
¢ &#162; &cent;
£ &#163; &pound;
¤ &#164; &curren;
¥ &#165; &yen;

HTML Colors

You can define HTML colors as string, number or hexadecimal value. But it is always recommended to define the value as hexadecimal. All browser supports hexadecimal color codes.

RGB Colors:

RGB stands for Red, Green and Blue. The HTML format for a RGB value is rgb (Value of RED, Value of GREEN, Value of BLUE). The value range are from 0 to 255. rgb(0,0,0) stand for Black color and rgb(255,255,255) stands for White color.

<body bgcolor="rgb(255,0,0)"> - Returns Red color
<body bgcolor="rgb(0,255,0)"> - Returns Green color
<body bgcolor="rgb(0,0,255)"> - Returns Blue color
<body bgcolor="rgb(255,255,255)"> - Returns White color
<body bgcolor="rgb(0,0,0)"> - Returns Black color

Hexadecimal Colors:

A hexadecimal color code starts with a hash(#) and followed by 6 alpha numeric value. Like #000000 stands for Black color and #FFFFFF stands for White color. The First 2 letter stands for Red, next 2 forGreen and last 2 letter for Blue color. The range is from Zero (0) to F. The Hexadecimal color values are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F total 16 digits.

The Hexadecimal colors created with a simple formula.

(First digit x 16) + Second digit = RGB Color value

If you write #000000 then as per the formula (0x16 + 0) = 0 so it Will be rgb(0,0,0) and it is black in color.

If you write #FFFFFF then as per the formula ((15 x16) +15) = 255 so the result will be rgb (255,255,255) and it is white in color.

So, with the help of the above formula you can convert any hexadecimal color code to RGB.

<body bgcolor="#FF0000"> - Returns Red color
<body bgcolor="#00FF00"> - Returns Green color
<body bgcolor="#0000FF"> - Returns Blue color
<body bgcolor="#FFFFFF)"> - Returns White color
<body bgcolor="#000000"> - Returns Black color

Convert RBG Color to Hexadecimal Color:

RED GREEN BBLUE Result
#
<bgcolor=”#FFFFFF”>
<bgcolor=”rgb(255,255,255)”>

Convert Hexadecimal Color to RGB Color :

RED GREEN BBLUE
#
<bgcolor=”#FFFFFF”>
<bgcolor=”rgb(255,255,255)”>

HTML Tables

Tables are defined with the <table> tag. A table is divided into rows (<tr>), and each row is divided into cells (<td>). The cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc.

Example:

<table>
<tr>
<td>&nbsp;</td>
</tr>
</table>

Tables and the Attribute:

Border: If you do not specify a border attribute the table will be displayed without any borders. Sometimes this can be useful, but most of the time, you want the borders to show.
To display a table with borders, you will have to use the border attribute:

<table border="1">
 <tr>
   <td>&nbsp;</td>
 </tr>
</table>

Width: You can specify the width of the table either in percentage or pixel.

<table border="1" width="100%" >
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

Cellspacing/ Cellpadding:

<table border="1" width="100%" 
cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>