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