This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is quick tutorial about How to detect mobile device and transfer visitor to mobile version of your website. | |
If you don't have a mobile responsive website and you created separate mobile version of website. | |
If user open your website in mobile then he/she should automatically redirect mobile version of your website. | |
Then the following function will help you to achieve this goal. | |
Like you have seen in many popular website like facebook.com. | |
If you open facebook on mobile's browser you will be automatically redirected on their mobile version m.facebook.com. | |
// Here is the function in PHP | |
<?php | |
$useragent=$_SERVER['HTTP_USER_AGENT']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suppose you have three sub domain like http://au.example.com, http://ng.example.com, http://in.example.com Australia, Nigeria, India. | |
And If some one type http://example.com then he/she redirected county specific url as per geo ip location. Here is the solution. | |
// By PHP | |
First of all download geoplugin library and call it on your page. | |
http://www.geoplugin.com/_media/webservices/geoplugin.class.phps | |
<?php | |
require_once('geoplugin.class.php'); | |
$geoplugin = new geoPlugin(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Here I have created a quick function in php to extract zip file. | |
Unzipping file is now very easy using php. | |
In php there is a function called ZipArchive::extractTo, using this predefined function you can easily extract zip archive. | |
*/ | |
function unzip($file, $location) { | |
$zip = new ZipArchive; | |
if ($zip->open($file) === TRUE) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getAge($dob) { | |
$today = date("Y-m-d"); | |
$diff = date_diff(date_create($dob), date_create($today)); | |
return $diff->format('%yYears, %mMonths, %dDays'); | |
} | |
// You can add the above function in your php library and use any where to calculate the age of the user by their date of birth. | |
echo getAge('19-10-1988'); | |
// Output: 27Years, 10Months, 19Days | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Below is a php time range function you can add in your php library and call it where you want to add time range dropdown. | |
function createTimeRange($startTime, $endTime, $interval = '15 mins', $format = '12') { | |
try { | |
if(!isset($startTime) || !isset($endTime)) { | |
throw new exception("Start or End time is missing"); | |
} | |
$startTime = strtotime($startTime); | |
$endTime = strtotime($endTime); | |
$currentTime = time(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function CCValidate($type, $cNum) { | |
switch ($type) { | |
case "American": | |
$pattern = "/^([34|37]{2})([0-9]{13})$/";//American Express | |
return (preg_match($pattern,$cNum)) ? true : false; | |
break; | |
case "Dinners": | |
$pattern = "/^([30|36|38]{2})([0-9]{12})$/";//Diner's Club | |
return (preg_match($pattern,$cNum)) ? true : false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parseDescription($html) { | |
// Get the 'content' attribute value in a <meta name="description" ... /> | |
$matches = array(); | |
// Search for <meta name="description" content="Buy my stuff" /> | |
preg_match('/<meta.*?name=("|\')description("|\').*?content=("|\')(.*?)("|\')/i', $html, $matches); | |
if (count($matches) > 4) { | |
return trim($matches[4]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------ Large screens ----------- */ | |
@media only screen and (min-width : 1824px) { | |
/* Styles go here.. */ | |
} | |
/* ------ Desktops and laptops ----------- */ | |
@media only screen and (min-width : 1224px) { | |
/* Styles go here.. */ | |
} | |
/* ------ Smartphones (portrait and landscape) ----- */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Github</title> | |
</head> | |
<body> | |
<script language="javascript"> | |
var message=""; | |
function clickIE() {if (document.all) {(message);return false;}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function convertSecToTime($sec){ | |
$date1 = new DateTime("@0"); //starting seconds | |
$date2 = new DateTime("@$sec"); // ending seconds | |
$interval = date_diff($date1, $date2); //the time difference | |
return $interval->format('%y Years, %m months, %d days, %h hours, %i minutes and %s seconds'); // convert into Years, Months, Days, Hours, Minutes and Seconds | |
} | |
echo convertSecToTime(246395678); | |
//OUTPUT: 7 Years, 9 months, 21 days, 19 hours, 14 minutes and 38 seconds | |
?> |