Wednesday, November 26, 2008

How to get the Square root of a numeric value using php - sqrt()

Following code will show you how to get the Square root of a given numeric value.


<?php

echo sqrt(4); // 2

echo sqrt(12); // 3.4641016151378

echo sqrt(16); // 4

echo sqrt(17); // 4.1231056256177

?>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Tuesday, November 25, 2008

How to round a floating point number in php - round()

Following code will show you several examples on how to round a floating numeric value as you like.


<?php

echo round(10.8); // 11
echo '<br />';
echo round(10.4); // 10
echo '<br />';

/*you can also set the number of precision,
or in other words number of decimal digits
you like to round the floating number
*/

echo round(10.837, 2); // 10.84
echo '<br />';
echo round(10.435767, 4); // 10.4358
echo '<br />';

?>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Monday, November 24, 2008

How to create a dynamic pdf file using php - FPDF fpdf.org

If you need to create dynamic or on the fly pdf files using php, usually we use PDFlib library. but PDFlib library sometimes not available in all hosting packages.
FPDF is a good alternative for PDFlib library, FPDF is a Free php class that you can easily include in you php code, really easy and simple to use FPDF is my choice when creating pdf files on the fly.

www.fpdf.org

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Thursday, November 20, 2008

How to split a string using javascript - split() method

Following code will show you how to split a string using a given separator.



<head>

<script type="text/javascript">

var my_string = "Hello My Name Is Kusal";
var split_var = my_string.split(" "); //separate by space

alert(split_var[0]); //Hello
alert(split_var[1]); //My
alert(split_var[4]); //Kusal

</script>

</head>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Friday, November 14, 2008

How to add RGB color values for select box or a DIV tag

Following code will show you two exapmles on how to add RGB color values to a Select DropDown Box and a DIV tag.


<body>

<select name="colors">
<option>Select</option>
<option style="background-color:rgb(200,250,300);">Color 1</option>
<option style="background-color:rgb(100,89,200);">Color 2</option>
<option style="background-color:rgb(65,89,50);">Color 2</option>

</select>

<br /><br />

<div style="background-color:rgb(200,100,100);">Hello</div>

</body>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Monday, November 10, 2008

How to search/scan files inside a directory using php - scandir()

Lets see how we can scan or search files inside a directory using php. You can use scandir() for this matter. scandir() will go through the given directory and return all the files in an array.


<?php

$dir_path = 'kusal/test'; //directory path
$list_files = scandir($dir_path);

//dumping the array
//hope you know how to access an array
echo '<pre>'; //html <pre> tags will format the output
print_r($list_files);
echo '</pre>';

/*
Output look like this

Array
(
[0] => .
[1] => ..
[2] => TextDocument.txt
[3] => kuppiya.doc
[4] => lion.ppt
[5] => test.as
)

*/

?>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Friday, November 7, 2008

How to delete a directory using php - rmdir()

Lets see how can we delete a folder using php.
You can use rmdir() function to do this task, before using this function you should remember that you can only delete empty folders


<?php

$path = 'path to directory'

//First Check if deleting a directory
if(is_dir($path))
{
//remove directory
if(rmdir($path))
{
echo 'Deleted';
}
else
{
echo 'error';
}
}
else
{
echo 'Not a directory';
}
?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, November 2, 2008

How to use getElementById in JavaScript

Following codes will show you how easy it is to use JavaScript getElementById to manipulate HTML elements.

Example 1 - On mouse over the text will be red, on mouse out it will be black again.


<html>
<head>

<script type="text/javascript">

function chng_color()
{
document.getElementById('my_div').style.color = 'red';
}

function normal_color()
{
document.getElementById('my_div').style.color = 'black';
}

</script>

</head>

<body>

<div id="my_div" onmouseover="chng_color()" onMouseOut="normal_color()">

This is the first example!!!

</div>

</body>
</html>


Example 2 - Get entered text of a text box and display it on a JavaScript alert box.


<html>
<head>

<script type="text/javascript">

function alrt_text()
{
var entered_text = document.getElementById('my_text_box').value;
alert(entered_text);
}

</script>

</head>

<body>

Your Text:
<input type="text" name="my_text_box" id="my_text_box" onBlur="alrt_text()" />

</body>
</html>


*Always remeber to give a id name for your HTML elements before using getElementById()

Get Free Sinhala IT Learning Videos Kuppiya.com

Subscribe To My Blog