<?php
function get_age($birth_date){
return floor((time() - strtotime($birth_date))/31556926);
}
echo " I am ".get_age("2000-05-10") ." years old";
?>
$path = $_FILES['image']['name']; $ext = pathinfo($path, PATHINFO_EXTENSION); echo $ext;
<?php $x = 100; $y = "100"; if($x == $y){ echo "Yes"; }else{ echo "No"; } ?>
<?php $x = 100; $y = "100"; if($x === $y){ echo "Yes"; }else{ echo "No"; } ?>
<?php /** * Grabs and returns the URL of current page. * @param none * @return URL of current page */ function grabCurrentURL(){ if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $url = "https://"; }else{ $url = "http://"; } $url .= $_SERVER['SERVER_NAME']; if($_SERVER['SERVER_PORT'] != 80){ $url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; }else{ $url .= $_SERVER["REQUEST_URI"]; } return $url; } echo grabCurrentURL(); ?>
<?php /** * Generates random passwords. * @param int Password Length (Default : 10) * @return Random String * @author Harshal Limaye (http://coffeecupweb.com/) */ function genPass($len = 10) { $charPool = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; $pass = array(); $length = strlen($charPool) - 1; for ($i = 0; $i < $len; $i++) { $n = rand(0, $length); $pass[] = $charPool[$n]; } return implode($pass); } echo genPass(); ?>
<?php //extract a file with php function extractZip($src,$dest){ $zip = new ZipArchive; $res = $zip->open($src); if ($res === TRUE) { $zip->extractTo($dest); $zip->close(); echo 'Files Extracted Successfully!'; } else { echo 'Extraction Failed!'; } } $src = "zip/file.zip"; $dest = "extractedfile/1/"; echo extractZip($src,$dest); ?>
//Creating a Zip File Using PHP function genZip($files = array(),$zipName){ $zip = new ZipArchive(); $zip->open($zipName.'.zip', ZipArchive::CREATE); foreach($files as $file){ $zip->addFile($file); } $zip->close(); }
//Usage of genZip function $files = array( 'file1.pdf', 'file2.pdf', 'file3.pdf', 'folder2/file4.pdf', 'folder2/file5.pdf' ); $zipName = 'myfiles'; genZip($files,$zipName);
Hello Friends! I am Ramana a part time blogger from Hyderabad.