Archive for December 21st, 2007

To Filter filenames or direcories in a specified matching pattern

Friday, December 21st, 2007

glob(string pattern,flags)

pattern->required, to specify the pattern search
flags->optional

Function returns an array of filenames or directories if it is matched in a specified pattern

otherwise it will returns an empty array.

example:

$temp_directory=glob(”*.*”);
The above function returns the array of all filenames placed inside the folder.

$temp_images=glob(images.”/”.”*.jpg*”);
print_r($temp_images);

The above function returns the array of all filenames who are all contains the extension as ‘jpg’ placed inside the image ‘folder.

Output like this;

Array ( [0] => images/webdesign.jpg
[1] => images/web_development.jpg )

Posted by Kalaivani S

Move content from one folder to other

Friday, December 21st, 2007

Function returns ‘true’  if it is moved all the content from source folder to destination folder otherwise returns ‘false’

Function Definition 

function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}

// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}

// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == ‘.’ || $entry == ‘..’) {
continue;
}

// Deep copy directories
if ($dest !== “$source/$entry”) {
copyr(”$source/$entry”, “$dest/$entry”);
}
}

// Clean up
$dir->close();
return true;
}

Function Call

$folder_move=copyr(source,destination);

source->source folder name

destination->destination folder name

Posted by Kalaivani S

To check if a file exists or not

Friday, December 21st, 2007

file_exists(string filename)

filename->To specify the full path of the file
Function returns ‘true’ if the file exist in the specified path, otherwise it will returns ‘false’.

<?php
$filename = ‘/optional/file_path/file_name.txt’;

if (file_exists($filename)) {
echo “File Exists”;
} else {
echo “File does not Exist”;
}
?>

Posted by Kalaivani S

Checking a value is number or not a number in Java Script

Friday, December 21st, 2007

isNaN(Number)

Number->Required.

function returns ‘true’ if a number is not a numeric otherwise it will returns false.

example:

<script type=”text/javascript”>

document.write(isNaN(67)+ “<br />”);
document.write(isNaN(-4.34)+ “<br />”);
document.write(isNaN(”Tryangled”)+ “<br />”);
document.write(isNaN(”2007/12/23″)+ “<br />”);
</script>

The above script will return like this.
false
false
true
true

Posted by Kalaivani S

To find date difference in between two dates

Friday, December 21st, 2007

DATEDIFF(exp1,exp2)

Function returns a value in day(s)  from one date to other date.
exp1 and exp2 are either date or datetimestamp expressions.
exp2 subtracted from exp1 like(exp1-exp2). Only the date parts of the values are used in the  calculation.

example:

SELECT id,name, datediff( Now( ) , enddate) AS Numofdays FROM `events` WHERE datediff( Now( ) , enddate) <30 LIMIT 0 , 30

Now() - Returns the datetimestamp 2007-12-21 10:05:42
enddate - date format like 2007-12-12
The above query will returns id,name and no of days  who are all having day(s) as less than 30

Posted by Kalaivani S