Showing posts with label PHP abs. Show all posts
Showing posts with label PHP abs. Show all posts

Monday, 20 July 2015

PHP: Expiry date code

<?php
    date_default_timezone_set ("Asia/Calcutta");
    $dateofreg1=date("M d Y");
    $puechese_date="08/13/2014";
    $startTime = strtotime($puechese_date);
    $endTime = strtotime($dateofreg1);
    $timeDiff = abs($startTime-$endTime);
    $numberDays = $timeDiff/86400;
    $numberDays = intval($numberDays);
    $validays="90";
    if($numberDays>$validays)
        {
        echo "Product Valid";
        }
    else
        {
        echo "Product Expired";
        }
?>

Tuesday, 2 June 2015

PHP: Calculate length difference in two strings

<?php // This will return a number of how many more characters the longest string has 
function str_compare_length($str1$str2){ 
    
$len1 strlen($str1); 
    
$len2 strlen($str2); 
    return 
abs($len1 $len2); 
} 

echo 
str_compare_length("This is the first string""This is the second string"); ?>