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!

Wednesday, September 10, 2008

How to get current URL using JavaScript

Simplest way to get the current browser URL using JavaScript is to use window.location.href
Look at the following code,


<script type="text/javascript">

var url = window.location.href;

document.write(url);

</script>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, September 7, 2008

How to reload parent window from a iframe

Lets see how we can reload or refresh parent page from a iframe. This is pretty simple with small piece of JavaScript - top.location.href
Look at the following code it has two pages.

frame.htm - parent


<HTML>
<HEAD>
<TITLE>Parent window</TITLE>
</HEAD>
<BODY>

<table border="1">
<tr>
<td>This is main</td>
<td><iframe src ="frame2.htm" width="100%">
</iframe></td>
</tr>
</table>

</BODY>
</HTML>



frame2.htm


<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>

<div onClick="top.location.href='frame.php'">
Click here to reload parent page</div>

</BODY>
</HTML>


Get Free Sinhala IT Learning Videos Kuppiya.com



Get custom programming done at GetAFreelancer.com!

Wednesday, September 3, 2008

How to change time zone using php - set default timezone for php

Surely when you develop a site, you need to change current server timezone to a different timezone for client requirements.
You can use date_default_timezone_set() to set default timezone for a given script. You can also edit the php.ini to change the timezone for all projects.

You can find list of supported timezones HERE for the above function

<?php

//before use of date_default_timezone_set

echo date("d-m-Y h:i:s A");

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

//set to US central time
date_default_timezone_set('US/Central');

echo date("d-m-Y h:i:s A");

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

Freelance Jobs