Tuesday, September 27, 2011

PHP Google PageRank Script

Finding Google PageRank for multiple URLs is difficult process,  Here is the my solution to find Google PageRank for multiple URLs at the same time, PR Finder PHP Script here is the best solution for Finding PR for any web url. hope this very usefull for your projects.


PHP Google PageRank finder Script 

Thursday, September 22, 2011

php time arithmetic and time difference between to times


Working with time different is very interesting in PHP, here is a function to find out the time difference and give the output in time format either it can be a 12hr/ 24hrs format. let us write this function to find out the
time arithmetic and time difference between to times using PHP. This function is very useful for compare the duration between two times, such employee work entry system, total hours of work


We can find the difference between Two time eg: 10:00:00 AM to 01:00:00 PM or 10:00:00 AM to 13:00:00 PM.


<?php
# Desc: function to return Time difference in between the two Times in a day
# Parm: Start_time end Time as 12hr/24hr format within single day
# Return: duration in time format: hh:mm:ss
function time_difference($start_time="11:00:00",$end_time="12:00:00")
{
list($h1,$m1,$s1)    =    split(':',$start_time);  
$startTimeStamp    =    mktime($h1,$m1,$s1,0,0,0);

list($h2,$m2,$s2)    =    split(':',$end_time);   

//check end time is in 12 hrs format:
if($h2 < $h1)
$h2+=12;

$endTimeStamp    =    mktime($h2,$m2,$s2,0,0,0); 
$time=abs($endTimeStamp - $startTimeStamp);

$value = array(
"hours" => "00",
"minutes" => "00",
"seconds" => "00"

);

if($time >= 3600){
$value["hours"] = sprintf("%02d",floor($time/3600));
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = sprintf("%02d",floor($time/60));
$time = ($time%60);
}

$value["seconds"] = sprintf("%02d",floor($time));

return implode(":",$value); 
}

echo time_difference("11:45:00","01:30:00");
echo "<br />";
echo time_difference("13:00:00","15:00:00");

//Output:
// 01:45:00
// 02:00:00

?>

Disable Enable Deselect Text Selection using JavaScript jQuery

As our subscriber request, how to Disable Enable Deselect Text Selection using JavaScript jQuery let us see how to work with prevent / disable text selection in web page using JavaScript / jQuery,



Here is the solution to prevent or disable enable text selection based on our requirement.

We can do the following:with this script:


Disable Text selection on your web page
Enable Text Selection on particular Area
Deselect Selected Text if you are in protected Area.


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Disable /Prevent Text Selection jQuery-JavaScript</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
// Begin:
// Jquery Function to Disable Text Selection
(function($){if($.browser.mozilla){$.fn.disableTextSelect=function(){return this.each(function(){$(this).css({"MozUserSelect":"none"})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).css({"MozUserSelect":""})})}}else{if($.browser.msie){$.fn.disableTextSelect=function(){return this.each(function(){$(this).bind("selectstart.disableTextSelect",function(){return false})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).unbind("selectstart.disableTextSelect")})}}else{$.fn.disableTextSelect=function(){return this.each(function(){$(this).bind("mousedown.disableTextSelect",function(){return false})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).unbind("mousedown.disableTextSelect")})}}}})(jQuery)
// EO Jquery Function

// Usage
// Load Jquery min .js ignore if already done so
// $("element to disable text").disableTextSelect();
// $("element to Enable text").enableTextSelect();
//

jQuery(function($) {
$("body").disableTextSelect();

$("#code").mouseover(function(){
 $("body").enableTextSelect();
});

$("#code").mouseout(function(){  

// Code for Deselect Text When Mouseout the Code Area
if (window.getSelection) {
  if (window.getSelection().empty) {  // Chrome
    window.getSelection().empty();
  } else if (window.getSelection().removeAllRanges) {  // Firefox
    window.getSelection().removeAllRanges();
  }
} else if (document.selection) {  // IE?
  document.selection.empty();
}
       
 $("body").disableTextSelect();
});
});
</script>

<style type="text/css">
<!--
body {
 margin-left: 10px;
 margin-top: 10px;
}

#code
{
 padding:20px;
 border:2px dashed #CCC;
 font-family:"Courier New", Courier, monospace;
 font-size:15px;
 background-color:#EEE;
}
-->
</style>
</head>

<body>
<h2>Disable /Prevent Text Selection jQuery-JavaScript</h2>
<p>Below this Code Area User can Allow to Select a Text in other Area text selection was disabled</p>
<p id="code">
$(".elementsToDisableSelectFor").disableTextSelect();</p>
<p>When you are leaving above code box selection was deselected! If selected !</p>
</body>
</html>


Download This Script     Live Demo

Monday, September 19, 2011

Copy Text to Clipboard Jquery JavaScript

Working with Clipboard in web page is have some security restriction on browser such Firefox and internet explorer. Here is the solution to copy text to clipboard with jQuery without any browser restriction.

zClip the effective clipboard handling jQuery with Flash Support we can make copy any region of text range with custom style and animated interface let us create it one example.

<h2>Copy Text to Clipboard Jquery JavaScript</h2>

<div style="padding:10px; border:1px dashed #ccc;">
<p id="description">
Welcome to ZeroClipBoard
</p>
<a id="copy-description">Copy above Text to Clipboard</a>

</div>
<br />

<textarea id="dynamic" style="padding:10px; border:1px solid #333; width:300px; height:100px;"></textarea>
<br /><br />
<a style="padding:4px; border:1px solid #333;" id="copy-dynamic">Copy</a><span id="msg" style="color:#090;"></span>

<script type="text/javascript">

$(document).ready(function(){

    $('a#copy-description').zclip({
        path:'js/ZeroClipboard.swf',
        copy:$('p#description').text(),
  afterCopy:function(){
            $('a#copy-description').text('Copied').fadeOut('slow');
        }
    });


    $('a#copy-dynamic').zclip({
        path:'js/ZeroClipboard.swf',
        copy:function(){return $('textarea#dynamic').val();},
        beforeCopy:function(){
            $('textarea#dynamic').css('background','green');
            $(this).css('color','orange');
        },
        afterCopy:function(){
            $('textarea#dynamic').css('background','white');
            $(this).css('color','purple');
            $(this).next('.check').show();
        }  
    });


});


</script>

id for the source element must call with the copy- instruction before initiate a clipboard handling with zClip

Download This Script     Live Demo     Download Script

Wednesday, September 14, 2011

Get yesterday date PHP

Here is the different way of Getting yesterday date with PHP
using strtotime() and mktime()  we can find the previous date in easy way.

# Using strtotime() function
// from Current Date
echo date("d-m-Y",strtotime("yesterday"));

# Using mktime() function
// from Specific date  eg: Oct-01-2011
echo date("d-m-Y",mktime(0,0,0,10,1,2011)-1);


Output:
13-09-2011
30-09-2011



Get First and Last date of the Month from given date with php

When working with date ranges we need to find out the month starting and end dates from the given date. here is the PHP function to Get First and Last date of the Month from given date with php

functions used:
list(), split(), date(), mktime(), array()




<?php

# Desc: Funcion to get First and Last date of the Month from Given Date
# Parm: $anyDate ( as YYYY-MM-DD format), $return Format (eg: d-m-Y );
# Return: Array with Two Values of First and Last Date

function first_last_date_of_month($anyDate,$returnFormat)
{
 // separate year, month and date
 list($yr,$mn,$dt)    =    split('-',$anyDate);    
 //Create time stamp of the first day from the give date.
 $timeStamp            =    mktime(0,0,0,$mn,1,$yr);
 //get first day of the given month
 $firstDay            =     date($returnFormat,$timeStamp);    
 //Find the last date of the month and separating it
 list($y,$m,$t)        =     split('-',date('Y-m-t',$timeStamp)); 
 //create time stamp of the last date of the give month
 $lastDayTimeStamp    =    mktime(0,0,0,$m,$t,$y);
 // Find last day of the month
 $lastDay            =    date($returnFormat,$lastDayTimeStamp);
 // return the result in an array format.
 $arrDay                =    array("$firstDay","$lastDay"); 
 return $arrDay;
}

//Usage
$month_range=array();
$month_range=first_last_date_of_month('2011-09-10','d-m-Y');
print $month_range[0];
echo "<br>";
print $month_range[1];

?>


Monday, September 12, 2011

Change/Update Photo with Ajax Image Uploader


A Member request us, How to create a Google Profile Like: Ajax Image Photo Uploader to Change/Update Photo with Ajax Image Uploader using PHP and jQuery. Here is the solution for the Image Uploader like Google Profile Style Ajax Image Uploader



In this example I have use HTML Input file object replacer "prettyfile plugin".
here you can download the jQuery prettyFile Plugin and Use the following code to replace a file input like a "Update Photo" link. and Turn your interface look like a Google Profile Photo update page with PHP Ajax Uploader without refreshing the page. Change/Update Photo with Ajax Image Uploader

Place the PHP Server Side Process on Page Top:

<?php session_start();

if(isset($_SESSION['updated_image']))
$existing_image=$_SESSION['updated_image'];
else
$existing_image='unknown.jpeg';


if(isset($_POST['image_process']))
{
 echo "<pre>";
 $filename=$_FILES['profile_photo']['name'];
 // Check whether the Uploaded file is Image file
 if(preg_match("/^[a-zA-Z0-9-_\.]+\.(jpg|gif|png|jpeg)$/",$filename))
 {
  // Check the Uploaded Image size is Less than or equal to 100 KB ( 1 KB == 1024 Bytes)
  if($_FILES['profile_photo']['size']<=102400)
  {
   $file_ext=end(explode(".",$filename));
   $filename="profile-".time().".$file_ext";
   if(move_uploaded_file($_FILES['profile_photo']['tmp_name'],"images/$filename"))   
   {
    $_SESSION['updated_image']=$filename;
   // Push Javascript Message on top Window  
   ?>
   <script type="text/javascript">
   window.top.window.top.UploadStatus(0,'<?=$filename?>');
   </script>
   <?php     
   }else
   {
   // Push Javascript Message on top Window  
   ?>
   <script type="text/javascript">
   window.top.window.top.UploadStatus(3);
   </script>
   <?php    
   }
   
  }else
  {
   // Push Javascript Message on top Window
  ?>
        <script type="text/javascript">
  window.top.window.top.UploadStatus(2);
  </script>
        <?php   
  }
 }else
 {
   // Push Javascript Message on top Window  
  ?>
        <script type="text/javascript">
  window.top.window.top.UploadStatus(1);
  </script>
        <?php
 }
 exit();
}


?>


Monday, September 5, 2011

jQuery Disable Browser Right click Context Menu in a web page

Prevent visitors from right clicking on your web page for some security reasons, we need to disable right click context menu when visitors attempt to make right click;  Here is the simple and useful jQuery Solution to disable Browser Right click context menu to support all major browsers.



<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
$(this).bind("contextmenu", function(e) {
                e.preventDefault();
            });
}); 
</script>

</head>

Friday, September 2, 2011

Select Country Drop Down based on country location with flag with PHP

Selecting country name from country drop down based on the visitors country location will increase visitors user friendliness for your web forms, Let us create How to create Auto Select Country Name based on visitors location based on Country Geo location and  IP Address. When Loading a page detect country name and locate a country flag based on country location.




Create a Free Account for IP to Location API from http://ipinfodb.com/ip_location_api.php  to get a API Key for IP to Location. and get the Country Flag from ip2Location database.
using the URL: http://www.ip2location.com/images/country/{ COUNTRY SHORT CODE} .gif

and Process the code as per the following:

Thursday, September 1, 2011

Google profile style Image Uploader Script with PHP and jQuery

A Member request us, How to create a Google profile photo update style Image uploader using PHP and jQuery. Here is the solution for the Image Uploader like Google Profiles Change Photo Style


In this example I have use HTML Input file object replacer "prettyfile plugin".
here you can download the jQuery prettyFile Plugin and Use the following code to replace a file input like a "Update Photo" link. and Turn your interface look like a Google Profile Photo update page with PHP Ajax Uploader without refreshing the page.

Place the PHP Server Side Process on Page Top:

<?php session_start();

if(isset($_SESSION['updated_image']))
$existing_image=$_SESSION['updated_image'];
else
$existing_image='unknown.jpeg';


if(isset($_POST['image_process']))
{
	echo "<pre>";
	$filename=$_FILES['profile_photo']['name'];
	// Check whether the Uploaded file is Image file
	if(preg_match("/^[a-zA-Z0-9-_\.]+\.(jpg|gif|png|jpeg)$/",$filename))
	{
		// Check the Uploaded Image size is Less than or equal to 100 KB ( 1 KB == 1024 Bytes)
		if($_FILES['profile_photo']['size']<=102400)
		{
			$file_ext=end(explode(".",$filename));
			$filename="profile-".time().".$file_ext";
			if(move_uploaded_file($_FILES['profile_photo']['tmp_name'],"images/$filename"))			
			{
				$_SESSION['updated_image']=$filename;
			// Push Javascript Message on top Window		
			?>
			<script type="text/javascript">
			window.top.window.top.UploadStatus(0,'<?=$filename?>');
			</script>
			<?php					
			}else
			{
			// Push Javascript Message on top Window		
			?>
			<script type="text/javascript">
			window.top.window.top.UploadStatus(3);
			</script>
			<?php				
			}
			
		}else
		{
			// Push Javascript Message on top Window
		?>
        <script type="text/javascript">
		window.top.window.top.UploadStatus(2);
		</script>
        <?php			
		}
	}else
	{
			// Push Javascript Message on top Window		
		?>
        <script type="text/javascript">
		window.top.window.top.UploadStatus(1);
		</script>
        <?php
	}
	exit();
}


?>