Category: php

How to calculate “time ago” in PHP

function time_ago($time)
$periods = array(“second”, “minute”, “hour”, “day”, “week”, “month”, “year”, “decade”);
$lengths = array(“60″,”60″,”24″,”7″,”4.35″,”12″,”10”);

$now = time();

$difference = $now – $time;
$tense = “ago”;

for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];

$difference = round($difference);

if($difference != 1) {
$periods[$j].= “s”;
return “$difference $periods[$j] ago”;
$time = strtotime(your date);
echo time_ago($time);

1 minute ago

Send email by using SMTP in PHP via localhost

Send email by using SMTP in PHP via localhost

* This example shows settings to use when sending via Google’s Gmail servers.
require ‘PHPMailerAutoload.php’;
//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = ‘html’;
//Set the hostname of the mail server
$mail->Host = ‘’;
//Set the SMTP port number – 587 for authenticated TLS
$mail->Port = 587;
//Set the encryption system to use – ssl (deprecated) or tls
$mail->SMTPSecure = ‘tls’;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication – use full email address for gmail
$mail->Username = “”;
//Password to use for SMTP authentication
$mail->Password = “gmail password”;
//Set who the message is to be sent from
$mail->setFrom(‘’, ‘Example’);
//Set an alternative reply-to address
$mail->addReplyTo(‘’, ‘Example’);
//Set who the message is to be sent to
$mail->addAddress(‘’, ‘To name’);
//Set the subject line
$mail->Subject = ‘Your Subject’;
//Replace the plain text body with one created manually
$mail->Body = ‘Message Body Text’;
//Attach an image file
$mail->addAttachment(‘images path’);
//send the message, check for errors
if (!$mail->send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
} else {
echo “Message sent!”;


How to add loading spinner image(page load images) in php using javascript

PHP Code:-


function preloader(){
document.getElementById(“loading”).style.display = “none”;
document.getElementById(“load_images”).style.display = “none”;
document.getElementById(“contents”).style.display = “block”;
window.onload = preloader;

#load_images{ background-color: #000000;
display: block;
height: 100%;
left: 0;
opacity: 0.6;
position: fixed;
top: 0;
width: 100%;
z-index: 9999;}
div#contents {
display: block;
#loading {
top: 50%;
left: 50%;
position: absolute;
cursor: wait;

<input type=”submit”>

Your Contain here……