Tag Archives: Open Source / E-commerce Solutions

PHP Array Sort Functions

The elements in an array can be either be sort ascending, descending, alphabetical and numerical order. Lets discuss the different sort function used in PHP.

– sort() – used to sort arrays in ascending order.
– rsort() – used to sort arrays in descending order.
– asort() – used to sort associative arrays in ascending order as per values.
– ksort() – used to sort associative arrays in ascending order as per key.
– arsort() – used to sort associative arrays in descending order as per  values.
– krsort() – used to sort associative arrays in descending order  as per key.
– shuffle() – used to randomizes the order of the elements in an array.

Sort arrays in ascending order sort()

<?php
$players = array("Sambir","Rupal","Aadarsh");
sort($players);
print_r($players);
?>

Output:
Array(
[0] => Aadarsh
[1] => Rupal
[2] => Sambir
)

Sort Array in Descending Order – rsort()

<?php
$players = array("Rupal","Sambit","Aadarsh");
rsort($players);
print_r($players);
?>

Output:
Array(
[0] => Sambir
[1] => Rupal
[2] => Aadarsh
)

asort()

<?php
$players = array("Sambir"=>"9","Rupal"=>"10","Aadarsh"=>"8");
asort($players);
print_r($players);
?>

Output:
Array(
[Aadarsh] => 8
[Sambir] => 9
[Rupal] => 10
)

ksort()

<?php
$players = array("Sambir"=>"9","Rupal"=>"10","Aadarsh"=>"8");
ksort($players);
print_r($players);
?>

Output:
Array(
[Aadarsh] => 8
[Rupal] => 10
[Sambir] => 9
)

ksort()

<?php
$players = array("Sambir"=>"9","Rupal"=>"10","Aadarsh"=>"8");
ksort($players);
print_r($players);
?>

Output:
Array(
[Aadarsh] => 8
[Rupal] => 10
[Sambir] => 9
)

arsort()

<?php
$players = array("Sambir"=>"9","Rupal"=>"10","Aadarsh"=>"8");
arsort($players);
print_r($players);
?>

Output:
Array(
[Rupal] => 10
[Sambir] => 9
[Aadarsh] => 8
)

krsort()

<?php
$players = array("Sambir"=>"9","Rupal"=>"10","Aadarsh"=>"8");
krsort($players);
print_r($players);
?>

Output:
Array(
[Sambir] => 9
[Rupal] => 10
[Aadarsh] => 8
)

shuffle()

<?php
$players = array("Sambir","Rupal","Aadarsh");
shuffle($players);
print_r($players);
?>

Output: /* Every time you refresh the value changes. */
Array(
 [0] => Aadarsh
[1] => Sambir
[2] => Rupal
)

PHP Data Handling

Handling data

Every programming language has its own set of data types that help developers to write programs. A data type is a classification of data . This could mean categorizing the the type of data as an amount of money, time or percentage. In PHP the data type can be broadly classified as scalar and compounddata types.

Scalar data type

Four type of data comes under the category of scalar data type: Boolean, integer, float and string.

Boolean

The Boolean data type can either be true or false. The numeric representation of the Boolean data type is 1 for true and 0 for false. The the fallowing example uses this data type:

<?php
$myVal = True; // Boolean variable type.
?>

Integer

An integer data type consist of numbers. You can use both negative or positive numbers like […-2,-1,0,1,2,3,…]. The size of an integer in PHP solely depends on the operating system that you are using. typically , the size of an integer can be up to 2 billion. In the fallowing code, $myVal is aninteger type variable with a value of 9:

<?php
 $myVal =9; //Is an integer.
?>

Float

A float is a data type that is also use for storing numbers. Usually floats are use to express decimal numbers, you can use the integer data type for non decimal numbers. Floats are also known as doubles or real numbers and have a precision of up 14 decimal places. In the fallowing code ,$floatVal is a float type variable and has a value of 9.98765:

<?php
$ floatVal = 9.98765 // Is a float type variable
?>

String

A string can be best defined as a series of characters. In PHP, a character is nothing but a byte. There are 256 different types of characters that can be used in strings. There is no maximum limit specification in relation to strings to PHP; therefore you need not worry about a very long string .There are two ways to specify a string discussed on fallowing sections.

Single quoted

You can use single quotes to specify a simple string. How ever when a string is enclosed in single quotes and it also contains some text enclosed in double quotes, you must use the backslash escape character to escape the single quotes. In other wards when you don’t want to parser to treat single quotes as syntax and display them as part of the output of the code, you need o use a back slash beforethe single quotes.

Lets consider a simple example to understand how single quotes are used to specify a string:

<?php
      echo 'This is my First String'; // will print the string on the screen.
?>

Now consider an example where double quotes are used within single quotes and single quotes is represent in the text enclosed in double quotes:

echo 'Rishi says: "I'm doing well "'; , //will display error.

When you try to execute this statement, an error message will appear on the screen. This is because when you use a single quote within double quotes, you need to escape the single quote with a backslash. In the fallowing statement is written correctly:

echo 'Rishi says: "I\'m doing well "'; , //is Correct now.

The output will be Rishi says: “I’m doing well”.

Another thing that you should remember when using single quoted string is that such string don’t support variable expansion: If you use a name of variable within single quote and try to print the value of a variable, the name of the variable will be printed instead of its value. Consider the fallowing example:

<?php
  $name='Rishi';
  echo 'Hello $name';
?>

The output will be Hello $name.
The correct syntax is

<?php
  $name="Rishi";
  echo "Hello $name";
?>

The output will be Hello Rishi.

Double quoted

A double quoted strings supports several other escape characters as follows
– \n: new line
– \r: carriage
– \t: Horizontal tab
– \\: backslash
– \$: Dollar sign
– \”: Double quote

HTML Audio

Play Audio in HTML Page

You can add audio or video to your html page. Either you can add video from www.youtube.com or you can add you own video by uploading the same to your own web server. But it is a bit tricky to show videos in your web page, and it is a little complicated to make it works in all browser.

Browser Supported Audio Formats:

File Format
.mid or .midi MIDI Musical Instrument Digital Interface
.mp3 or .mpga MP3 MPEG-1 or MPEG-2 Audio Layer 3
.WMA WMA Windows Media Audio
.wav WAVE Waveform audio format
.rm or .ram Real Audio

Play Background Music in HTML Page

<BGSOUND src="music.mid" 
 balance=0 
 delay=10
 loop = -1>

Play Audio in HTML

<audio controls="mycontrol" height="50" width="50">
 <source src="music.mp3" type="audio/mp3" />
 <source src="music.ogg" type="audio/ogg" />
<embed height="50" width="50" src="music.mp3" />
</audio>

Using the HTML5 “audio” Element

<audio controls="controls">
  <source src="music.mp3" type="audio/mp3" />
  <source src="music.ogg" type="audio/ogg" />
Your browser does not support this audio format.
</audio>

Click here to know more about .ogg file format.

Using “object” Element

<object width="100" height="100" data="music.mp3"></object>

Using “embed” Element

<embed width="100" height="100" src="music.mp3" />

The Yahoo Media Player

<script type="text/javascript" src="http://mediaplayer.yahoo.com/js">
</script>
<a href="music.mp3">Play Music</a>

For More detail about Yahoo audio player please visit http://webplayer.yahoo.com/

HTML Attributes

Many HTML tags have a unique set of their own attributes. These attributes are divided into core attributesinternationalization attributes, and scripting events. Attributes are always specified in the start tag and come in name/value pairs like: name=”value”

Example

<a href="http://www.a2zwebhelp.com">Link to my website.</a>
<p id="firstp">This is my first paragraph.</p>
<h2 align="center" title="center text">Centered Heading</h2>

HTML Attributes with category

Category Attributes Name
Core Attributes id <p id=”myid”>My Text.</p>
class <div clsss=”newclass”> Text </div>
name <form name=”arup”></form>
style <span style=”font-family: arial”> Arial</span>
title <h1 title=”Heading”> Heading </h1>
alt <img src=”” alt=”my image”>
align <p align=”left”></p>
valign <td valign=”top”>&nbsp;</td>
bgcolor <td bgcolor=”#808080″>&nbsp;</td>
background <td background=”filepath”>&nbsp;</td>
width <img width=”100px”>
height <img width=”100px” height=”100px”>
Internationalization Attributes LANG <span lang=en>Welcome</span>
DIR
Common Scripting Events ONCLICK mouse button is clicked on an element.
ONDBLCLICK mouse button is double-clicked on an element
ONMOUSEDOWN mouse button is pressed over an element
ONMOUSEUP mouse button is released over an element
ONMOUSEOVER mouse is moved onto an element
ONMOUSEMOVE mouse is moved while over an element
ONMOUSEOUT mouse is moved away from an element
ONKEYPRESS a key is pressed and released over an element
ONKEYDOWN a key is pressed down over an element
ONKEYUP a key is released over an element

Open Source Platform

“IWCn excels in implementation of Open Source technology for business      solutions “

OPEN SOURCE / E-COMMERCE SOLUTIONS

Setting up and customizing an ecommerce solution requires special technology and domain experience. Itransition will guide you through the process of setting up your domain name, merchant account, payment gateway, shopping cart, order and product management, search engine optimization and hosting.

Continue reading