Skip to main content

Posts

Showing posts from November 21, 2012

PHP in-built functions

PHP Basic Functions   Function Description array() Creates an array array_push() Inserts one or more elements to the end of an array shuffle() Shuffles an array sizeof() Alias of count() sort() Sorts an array count() Counts elements in an array, or properties in an object uasort() Sorts an array with a user-defined function and maintain index association date() Formats a local time/date getdate() Returns an array that contains date and time information for a Unix timestamp mktime() Returns the Unix timestamp for a date strftime() Formats a local time/date according to locale settings strptime() Parses a time/date generated with strftime() time() Returns the current time as a Unix timestamp chdir() Changes the current directory dir() Opens a directory handle and returns an object addcslashes() Returns a string with backslashes in front of the specified characters addslashes() Returns a string with backslashe...

PHP functions

A function is a block of code that can be executed whenever required. A function will be executed by a call to the function. You may call a function from anywhere within a page. Give the function a name that reflects what the function does. The function name can start with a letter or underscore but not a number. Syntax function functionName() { code to be executed } Creating a simple function <?php function hello(){ echo “This is my first simple function”; } //call php function hello(); ?> PHP function with parameters <?php function myHello($firstname) { echo “Namaste “. $firstName . “!<br />”; } //call function myHello(“Ram”); ?> Display: Namaste Ram ! Another example <?php function addNumber($num1, $num2) { $num3= $num1+$num2; echo “The sum is”.$num3; } //function call addNumber(15,25); ?>

Conditional Statements

There are three types of conditional statements. They are as follows: if statement if else statement switch statement 1) if statement : This statement is used to execute some code only if a specified condition is true. Syntax: if(condition) { write statement here }  2) if….else statement: If a condition is true, one code is executed and another code if the condition is false. Syntax: if(condition) { write statement here } else if(condition) { write statement here } else { write statement here } 3) switch statement: This statement is used to select one of many blocks of code to be executed. Syntax: switch(variable) { case 1: write statement to be executed break; case 2: write statement to be executed break; case 3: write statement to be executed break; default: write statement to be executed } Examples  1) if statement <?php $day=”Fri”; if($day==”Fri”) { echo  “Have...

PHP Loops

There are four types of loops in PHP. They are as follows: 1) while loop 2) do…while loop 3) for loop 4) foreach loop  1) while loop: Loops through a block of codes while a specified condition is true. Example: <?php $i=1; while($i<=5) { echo  “The number is ”.$i.”<br/>”; $i++; } ?> 2) do…while loop: Loops through a block of code once and then repeats the loop as long as a specified condition is true. Example: <?php $i=1; do{ $i++; echo “The number is ”.$i.”<br/>”; } while($i<=5); ?> 3)for loop: Loops through a block of code a specified number of items. Example: <?php for($i=1;$i<=5;$i++) { echo “The number is ”.$i.”<br/>”; } ?> 4) foreach loop: Loops through a block of code for each element in an array. Example: <?php $x=array(“one”,”two”,”three”); foreach($x as $value) { echo $x.”<br/>”; } ?>

PHP Operators

S.no Operator Operation 1 Addition (+) 4+5=9 2 Subtraction (-) 10-2=8 3 Multiplication (*) 2*4=8 4 Division (/) 15/5=3 5 Modulus (%) 5%2=1, 10%8=2, 10%2=0 6 Increment (++) x=5 x++ is equivalent to x=x+1 x=6 7 Decrement (--) x=5 x—is equivalent to x=x-1 x=4

Variables in PHP

Variables are used for storing a values, like text strings, numbers or arrays. When a variable is declared, it can be used over and over again in your script. All variables in PHP start with a ‘$’sign symbol. $var_name=value; For example: <?php $txt=”Hello world”; echo $txt; ?>

Comments in PHP

Comments are given so that it shouldn’t get displayed in the front-end but the programmer should always knew the idea behind the coding. Single line comment <?php // This is a comment ?> Multi-line comments <?php /* This is a comment block. This is a comment block. This is a comment block.*/ ?>

CSS Vertical Menu

Css Vertical Menu can be build using following code : Vertical Menu #1 Code <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <title>Css Simple Menu</title> <style type=”text/css”> #vmenu{ margin:0px; padding:0px; }

CSS Multilevel menu (Horizontal Multilevel Menu)

To create a multilevel menu in CSS, one should use the nesting of unordered list. The below given is the simple multi- level menu.

Css Simple Menu

Simple one level menu can be created using unordered list with the help of CSS properties. Below given is a very simple examples:

CSS List

CSS allows you to customize the lists that can be made with HTML  to the extent that even images can be used as bullet points for unordered lists. CSS List Style Type If you want to use something different from the default numbering of ordered lists, or the bullets/discs of unordered lists, then all you have to do is choose a different style for your lists. CSS allows you to select from a wide variety of different list item shapes. Unordered list styles: square, circle, disc (default), and none Ordered list styles: upper-alpha, lower-alpha, upper-roman, lower-roman, decimal (default), and none Code:

CSS Margins and Padding

Margin and padding are the two most commonly used properties for spacing-out elements. A margin is the space outside of the element, whereas padding is the space inside the element. The four sides of an element can also be set individually. margin-top, margin-right, margin-bottom, margin-left, padding-top, padding-right, padding-bottom and padding-left are the self-explanatory properties you can use.

Css Layers(z-index)

It refers to apply the z-index property to elements that overlap with each other. The z-index property when used in conjuction with the position property, enable you to specify which element should appear on top in the event of an overlap.

Overflow property

To control the overflow of the fixed box.There are four types of overflow property and they are: visible(default), hidden, scroll and auto. visible overflow: If you don’t set the overflow property at all the default is visible. For eg: .box{ overflow:visible; height:20px; }

Css Positions

You can put any HTML element at wherever position in the page or absolute based on its parent element. Relative Positioning: It changes the position of the HTML element relative to where it normally appears For example: <div style=”position:relative;left:80px; top:2px; background-color:yellow;”> This div has relative positioning </div>

Css Dimensions

The following are the Css dimensions used. height: sets the height of an element max-height: sets the maximum height of an element max-width: sets the maximum width of an element min-height: sets the minimum height min-width: set the minimum width width: sets width line-height: set the height of a line of text

Css Outlines

An outline is a line that is drawn around elements, outside the border edge, to make the element “standout”; The outline properties specifies the style, color and width of an outline. outline outline-color outline-style outline-width

CSS Border

Css allows you to set styles for the border of any HTML element. It also provides you with a way of setting border styles for one or more sides of an element. Setting Borders on all sides. border-width border-style border-color