Share your pages on Social Networking websites

To share your pages on social Networking sites is an easy Task now.

You can share your page to your friend on their WhatsApp also.

Click Here to download the script needed to run WhatsApp share.

<script type="text/javascript">if(typeof wabtn4fg==="undefined"){wabtn4fg=1;h=document.head||document.getElementsByTagName("head")[0],s=document.createElement("script");s.type="text/javascript";s.src="http://www.itrusoft.com/blogbysid/blogfiles/whatsapp-button.js";h.appendChild(s);}</script>

replace the existing URL with your site URL and link the whatsapp JS to it.

<?php
$shareSource = urlencode('blogbysid.wordpress.com');
$shareActualUrl = 'https://blogbysid.wordpress.com/2013/09/03/google-maps-in-grayscale/';
$shareActualTitle = 'Google Maps in Grayscale';
$shareUrl = urlencode($shareActualUrl);
$shareTitle = urlencode($shareActualTitle);
$shareDescription = urlencode('This example displays a grayscale saturation in Google maps:');
$shareImgSrc = urlencode('https://blogbysid.files.wordpress.com/2013/09/gray-google-map.jpg');
$hashtags = 'blogbysid'; // comma separated list of hashtags, with no # on them
?>

replace these title, links with yours

The below code generates the link to share your page on respective pages

<a title="WhatsApp" href="whatsapp://send" data-text="<?php echo $shareActualTitle; ?>" data-href="<?php echo $shareActualUrl; ?>" class="wa_btn wa_btn_s">WhatsApp</a>

<a title="Facebook" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $shareUrl; ?>&t=<?php echo $shareTitle; ?>">Facebook</a>

<a title="Twitter" target="_blank" href="https://twitter.com/share?text=<?php echo $shareTitle; ?>&url=<?php echo $shareUrl; ?>&hashtags=<?php echo $hashtags; ?>">Twitter</a>

<a title="Google Plus" target="_blank" href="https://plus.google.com/share?url=<?php echo $shareUrl; ?>">Google Plus</a>

<a title="LinkedIn" target="_blank" href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo $shareUrl; ?>&title=<?php echo $shareTitle; ?>&summary=<?php echo $shareDescription; ?>&source=<?php echo $shareSource; ?>">LinkedIn</a>

<a title="Pinterest" target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php echo $shareUrl; ?>&media=<?php echo $shareImgSrc; ?>&description=<?php echo $shareDescription; ?>">Pinterest</a>

Sorting a Multi-Dimensional Array with PHP

//an array of some songs I like
$songs =  array(
		'1' => array('artist'=>'The Smashing Pumpkins', 'songname'=>'Soma'),
		'2' => array('artist'=>'The Decemberists', 'songname'=>'The Island'),
		'3' => array('artist'=>'Fleetwood Mac', 'songname' =>'Second-hand News')
	);

The problem is thus: I’d like to echo out the songs I like in the format “Songname (Artist),” and I’d like to do it alphabetically by artist. PHP provides many functions for sorting arrays, but none will work here. ksort() will allow me to sort by key, but the keys in the $songs array are irrelevant. asort() allows me to sort and preserves keys, but it will sort $songs by the value of each element, which is also useless, since the value of each is “array()”. usort() is another possible candidate and can do multi-dimensional sorting, but it involves building a callback function and is often pretty long-winded. Even the examples in the PHP docs references specific keys.
Continue reading

Display Expire time in Days, Hours, Minutes and Seconds


<?php
date_default_timezone_set('Asia/Calcutta');
function datediff( $date1, $date2 )
{
$diff = abs( strtotime( $date1 ) - strtotime( $date2 ) );

return sprintf
(
"%d Days, %d Hours, %d Mins, %d Seconds",
intval( $diff / 86400 ),
intval( ( $diff % 86400 ) / 3600),
intval( ( $diff / 60 ) % 60 ),
intval( $diff % 60 )
);
}

print datediff( "2015-05-11 14:55:00", "now" ) . "n";

Create Slug for a string

Regular expression function that replaces spaces & special characters between words with hyphens


function create_slug($string) {
	// removing special characters from the string
	$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
	// removing multiple - generated in slug
	$slug = preg_replace("/[-]+/", '-', $slug);
	// lower case slug string
	$slug = strtolower($slug);
	// removing - from the first & last place if any
	$slug = trim($slug, "-");
	return $slug;
}

echo create_slug(" This ~` is ?><:{}|][;/.,]+_)(*&^%$#@!) 'MY TITLE' for------this post. ");

Regular Expression

Following are the important notations of regular expression:

[ ] matches only one character position with provided in between 
- it is used to match limit range of char or number provided in [ ] e.g [0-9]
^ it is used to negate the expression if it is inside of [ ] e.g [^fF]
^ outside [ ] means to match only at the begenning of target string
$ user to match at the end of target string
. used to match any char in this position
\ escape character
? matches preceding char occurance 0 or 1 times only
* matches preceding char occurance 0 or more times only
+ matches preceding char occurance 1 or more times
{ } matches preceding char occurance n times exactly e.g [char]{n}
{n,m}