Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-includes/theme.php on line 507

Deprecated: Assigning the return value of new by reference is deprecated in /home/tryangle/public_html/blog/wp-content/plugins/codesnippet/codesnippet.php on line 248
Tryangled Dev » 2007 » December

Archive for December, 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

To find out duplicate rows in the table

Thursday, December 20th, 2007

SELECT sheet_id, COUNT( sheet_id ) AS NumOccurrences
FROM candidate_sheet
GROUP BY sheet_id
HAVING
(COUNT( sheet_id )>1)

The above query will returns the sheet_id and number of occurrences of sheet_id who’s sheet_id will exist more than one time in the table.

Posted by Kalaivani S

validate the number in numeric format

Wednesday, December 19th, 2007

<?php
function PhoneCheck($number)
{
return preg_match(”/^[(\[]?\d{3}[)-\.\] ]*\d{3}[-\. ]?\d{4}$/”, $number, $scrap);
}
?>

is one way…personally i save only the numbers and throw the rest away..makes it simpler and you can always change the display code to format a number for a particular use. 

$phone = preg_replace(”[^0-9]”,”",$_POST[’phone’]);

Posted by Suresh B

How do I go back in the browser in PHP?

Wednesday, December 19th, 2007

You can use javascript to back a page: history.go(-1)

Eg:

Code:
<a href=”#” onclick=”history.go(-1)”>Back</a>

Or you can use PHP code to determine which page they came from and create link like:

Code:
<a href=”<?=$_SERVER[’HTTP_REFERER’]?>”>Back</a>

Posted by Suresh B