Monday, October 27, 2008

How to convert a string into a lowercase letters (simple letters) using php

Following code will show you how to convert a string of letters into lowercase(simple) using php strtolower() function.


<?php

$my_string = "This STRING has UPPERCASE letters";
$my_string = strtolower($my_string);
echo $my_string;

//Output: this string has uppercase letters

?>



Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, October 19, 2008

How to validate a date to see if its a correct date format using php

You have function called checkdate() where you can validate a input date is actually a correct date format. checkdate() will validate Gregorian date, so we need to properly give the parameters for the checkdate() function.
checkdate($month, $day, $year) - will return true or false


<?php

//checkdate($month, $day, $year) - format

$month = 10;
$day = 12;
$year = 2008;

echo 'Valid Date Example: ';

if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}

echo '<br /><br />';
echo 'Invalid Date Example: ';

//Invalid date
$month = 14; // month is wrong
$day = 12;
$year = 2008;

if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Wednesday, October 15, 2008

How to join array elements together using php - implode()

Lets see how we can join elements in a array to a comma separated String (You can use any separator you want with implode().)
simply use implode and you are done


<?php

$array_items = array('item1', 'item2', 'item3');
$string_with_comma = implode(",", $array_items);

echo $string_with_comma; // item1,item2,item13

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, October 12, 2008

How to find the array key for a given value using php - array_search()

You can use array_search() for searching a value within a given array.
You can search a given value in an array and return the relevant key using array_search()


<?php
$array = array(0 => 'Tom', 1 => 'Kusal', 2 => 'Jerry', 3 => 'Jhonny');

$key = array_search('Tom', $array);
echo $key; // $key = 0;

/* sample
$key = array_search('Kusal', $array); // $key = 1;
$key = array_search('Jerry', $array); // $key = 2;
$key = array_search('Jhonny', $array); // $key = 3;
sample */


?>


Get Free Sinhala IT Learning Videos Kuppiya.com

Subscribe To My Blog

Wednesday, September 24, 2008

How to check if a given value exists in an array using php

If you want to check if a given value exists in a php array variable, you can simply use the php in_array() function. This function will return true if searched value exists else will return false.


<?php

$names = array("Bill", "Kusal", "Rex", "Jhon");

if(in_array("Kusal", $names))
{
echo "Kusal is here";
}
else
{
echo 'Not Found';
}

?>



Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Monday, September 22, 2008

How to make a string all Uppercase using php - Make a word capital

Lets see how we can convert a given string into all uppercase letters using php
We can use the strtoupper() function to do the trick for us


<?php
$word = "we Love php";
$word = strtoupper($word);
echo $word; //WE LOVE PHP
?>





Get custom programming done at GetAFreelancer.com!

Friday, September 19, 2008

How to add date and time using php - mktime()

When you need to add time or add date, you don't need to explode your time string and add time or date separately for each part, you can simply use php's powerful mktime() function to do all the work.


<?php

echo 'Original Date/Time <br />';

//mktime(hour,minute,second,month,day,year)

echo date("h:i:s d-m-Y", mktime(10, 15, 20, 8, 20, 2008));
//10:15:20 20-08-2008

echo '<br /><br />';

echo 'Date/Time Added by 1';
echo '<br />';

echo date("h:i:s d-m-Y", mktime(10+1, 15+1, 20+1, 8+1, 20+1,2008+1));
//11:16:21 21-09-2009

?>



Get Free Sinhala IT Learning Videos Kuppiya.com

Subscribe To My Blog

Friday, September 12, 2008

How to change background color in a DIV tag on onmouseover

As a web developer it's essential that you are comfortable with CSS styles, you maybe a php,.net,ruby on rails developer but it's always good to have some style tricks in your pocket so that you don't need to find a web designer to do it for you. following code is a simple way to change the color of the background of a DIV tag on mouse over event.


<div onmouseover="this.style.background='green';"
onmouseout="this.style.background='white';">
kuppiya.com
</div>


Get Free Sinhala IT Learning Videos Kuppiya.com

Get custom programming done at GetAFreelancer.com!