Shorten your link using bitly API

Below is the code on how to make use of bitly API but first things first. In order to use the code below, you must create an account in bitly to gain your login and API Key which are both required in the API call. Once you have that setup, copy and paste the code below and you’re ready to get rollin’.

function makeBitlyUrl($url, $login, $apiKey, $format = 'xml', $version = '2.0.1')
{
	//First, you need to create the URL
	$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$apiKey.'&format='.$format;
	
	//Then, get the return data from the API call
	$response = file_get_contents($bitly);
	
	//Parse data depending on your preferred format
	if( strtolower( $format ) == 'json' )
	{
		$json = @json_decode($response,true);
		return $json['results'][$url]['shortUrl'];
	}
	else //Default is XML
	{
		$xml = simplexml_load_string($response);
		return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
	}
}

$shortenedUrl = makeBitlyUrl('https://example.com', 'winnie', 'R_123456789abcde', 'json');

PHP: How to detect the device used by a user?

iOS
if (stripos($_SERVER['HTTP_USER_AGENT'],"iPod") || stripos($_SERVER['HTTP_USER_AGENT'],"iPhone") || stripos($_SERVER['HTTP_USER_AGENT'],"iPad"))
	$device = 'ios';
Android
if (stripos($_SERVER['HTTP_USER_AGENT'],"Android") )
	$device = 'android';
LG Mobile
if (stripos($_SERVER['HTTP_USER_AGENT'],"webOS"))
	$device = 'webOs';

JavaScript: How to detect the browser currently used by the user?

Opera
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
At least Safari 3+: “[object HTMLElementConstructor]”
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;

Check if an input is a string or a url

In this scenario, we are not checking if this is a valid url but we just want to differentiate if it is a string or a url.

var str = 'winnieverzosa.com'
isURL(str);
function isURL(str){
	if ( str.match(/.*\..*/) ){
		alert(str + ' is a URL');
	} else {
		alert(str + ' is NOT a URL');
	}
}

jQuery Validate URL

function isUrlValid(url) {
    return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url);
}