Posts

Accurate time using PHP

<?php     function ezDate($d) {         $ts = time() - strtotime(str_replace("-","/",$d));                 if($ts>31536000) $val = round($ts/31536000,0).' year';         else if($ts>2419200) $val = round($ts/2419200,0).' month';         else if($ts>604800) $val = round($ts/604800,0).' week';         else if($ts>86400) $val = round($ts/86400,0).' day';         else if($ts>3600) $val = round($ts/3600,0).' hour';         else if($ts>60) $val = round($ts/60,0).' minute';         else $val = $ts.' second';                 if($val>1) $val .= 's';   ...

Date/Time in PHP

<?PHP      //Current Year     $year = date("Y");      //2013         //Current Month     $month = date("m");    //08         //Current day     $day = date("d");     //12         //Tomorrow's day     $day = date("d")+1;    //13             //TODAY'S DATE          $start =  date("Y-m-d");     //2013-08-12               //1 MONTH FROM TODAY          $end = date("Y-m-d",strtotime("+1 months"));     //2013-09-12          //5 DAYS FROM TODAY         $reminder = date("Y-m-d",strtotime("+5...

Birthdate validation for less than 18 in PHP

Here is the code to validate for birthdate, //Validate for users below 18 only function birthdate($then, $min) {   // $then will first be a string-date   $then = strtotime($then);   //The age to be less than 18   $min = strtotime('+18 years', $then);    if(time() < $min)   {      return false;   }   else {      return true;   } }

ul li for 4 partition

Code:    {assign var="productByLine" value = "4"}    {assign var="productLineTurn" value = "1"}    {assign var="tr" value = "true"}    {assign var="turns" value = "1"}        <table style="border: 1px solid #CCC;">       {foreach from=$upcomingEvent item=product name=products}                    <!-- Start a new line -->          {if $tr eq "true"}             <tr>             {assign var="productLineTurn" value = "1"}             {assign var="tr" value = "false"}          {/if}              ...

Facebook - Sharing with site image, title and description

Facebook crawls the page to decide how to display it. In order to specify the share to look according to your liking, you will have to add open graph tags . Below is the example: <meta property="og:image" content="URL OF IMAGE" /> <meta property="og:title" content="TITLE TO APPEAR" /> in the header of each page of your site. You can know about it from here: http://support.sharethis.com/customer/portal/articles/475079-share-properties-and-sharing-custom-information#Open_Graph_Tags Please remove the "st" properties from the span tag code, the span tag should look like - Hello User, <span class='st_facebook_large' ></span>

Javascript: Textarea should replace break on enter

Use this code to  get break as user enters in the textarea. Hope this helps! <html> <head> <title>Insert new lines dynamically</title> <script type = "text/javascript">  function fillTarg() {  var TARG = document.getElementById("newtext")  var AREA = document.getElementById("textarea")   TARG.innerHTML = AREA.value.replace(/\n/g,"<br>") // Replace break on user enters  TARG.innerHTML = AREA.value.replace(/\s/g,"&nbsp;")  // Replace space on user enters } </script> </head>   <body> <textarea style="width:450px; height:150px;" id="textarea"  onKeyUp="fillTarg()">Click on the button below to add some lines!</textarea> <br><br> <span id="newtext"> </span> </body> </html>

Javascript - Color box using URL or iframe

We have to use this script where the output will take from url, Javascript: ======== <script> function getParameterByName(url, name) {   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   var regexS = "[\\?&]"+name+"=([^&#]*)";   var regex = new RegExp( regexS );   var results = regex.exec(url);   if( results == null )     return "";   else     return decodeURIComponent(results[1].replace(/\+/g, " ")); } $(document).ready(function(){ $('.dialog-open').each(function() {    $(this).colorbox({      height: 600,      width: 800,      iframe: true,      href: "contact?id=" + getParameterByName($(this).attr("href"), "id")    }); }); </script> HTML ===== <a href='test.php?id=$id' class="dialog-open"> test </a>    Source: http://www.jacklmoore.com/colorbox/