Wednesday, January 28, 2009

How to find current shell in Ubuntu / Linux

There are several shells you can work on Linux, BASH (Bourne-Again SHell), CSH(C SHell), KSH (Korn SHell) are some of the famous ones.
So how you know what is your current SHELL?
try the following command in your terminal.
echo $SHELL

Find current working shell

Saturday, January 24, 2009

How to put text content around a image using DIV





These are some sample text to show you how to put content like this around the images. This technique is useful when you are writing articles with images. You should remember to set vspace and hspace properties in the img tag to correctly format the content. Look at the following code try it your self





<table border="0" align="center" width="375">
<tr><td>
<div id="image"><img src="http://kuppiya.com/toplogo2.jpg"
vspace="3" align="left" border="0" hspace="3" /></div>
<div>These are some sample text to show you how to put content
like this around the images. This technique is useful when you are
writing articles with images. You should remember to set
vspace and hspace properties in the img tag to correctly format the
content. Look at the following code try it your self </div>
</td></tr>
</table>

Tuesday, January 20, 2009

How to merge two arrays together in php

When you need to join or merge two arrays together you can use the php array_merge() function to do it. This function will return the merged array.
Look at the following code and see how the index reassigned.


<?php

$first_array = array(1, 2, 3, 4, 5, 6);
$second_array = array(10, 9, 7, 3, 5);

$new_array = array_merge($first_array, $second_array);

echo '<pre>';
print_r($new_array);
echo '</pre>';

/*

OUTPUT

Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 10
[7] => 9
[8] => 7
[9] => 3
[10] => 5
)

*/

?>

Thursday, January 15, 2009

Remove duplicate values from an array in php - array_unique

You can use array_unique() function get unique values out of a long array.
function will return an array with unique values and will preserve the keys.


<?php

$my_array = array(1, 2, 3, 3, 4, 4, 1, 5, 6, 6, 7);

$my_unique_array = array_unique($my_array);

echo '<pre>';
print_r($my_unique_array);
echo '</pre>';

/*
OUTPUT:

Array
(
[0] => 1
[1] => 2
[2] => 3
[4] => 4
[7] => 5
[8] => 6
[10] => 7
)


*/
?>

Sunday, January 11, 2009

How to put a value to the end of an array - array_push()

You can use array_push() function to pass a value to the end of an array.
array_push(current_array , value )
array_push() accept two basic parameters, first one is the current array you want to push the value. after that you can pass any number of values separated by commas.


<?php

$my_array = array('Me', 'You');
array_push($my_array, 'Others');

print_r($my_array);

/*
Array
(
[0] => Me
[1] => You
[2] => Others
)

*/

?>

Wednesday, January 7, 2009

How to find a specific file type inside a folder using php - glob()

Using the glob() function you can search only for a given file type inside a folder.
glob() will return an array containg all file names with the given file type.
Following code will show you how to get a list of only .gif image files from the image folder.


<?php

//get only .gif files from images folder
$files_list = glob("images/*.gif");

foreach($files_list as $files)
{
echo $files;
echo '<br />';
}

?>

Thursday, January 1, 2009

How to remove an element from an array variable in php

php unset() will not only unset a single variable, you can also remove elements from a array variable using unset(). Look at the following code.
See that the index 2 is not in the array any more and the $my_array is not in the correct index sequence. you can reassign indexes using the array_values()


<?php

$my_array = array('Hello', 'Bye', 'Kusal', 'kuppiya');

unset($my_array[2]); // remove kusal from array

print_r($my_array);

/*
Result:

Array ( [0] => Hello [1] => Bye [3] => kuppiya )

*/
?>


Get custom programming done at GetAFreelancer.com!