Thursday, 24 November 2011

Get the number of days between two dates.

$date1 = date('2011-11-01');

$date2 = date('2011-11-09');

echo (strtotime($date2) - strtotime($date1))/(60*60*24);

8 would be answer

Monday, 13 June 2011

Run PHTML file as HTML in Dreamweaver

Go to the folder where the dreamweaver is installed...... (Try to install some other drive where the windows is not installed... due to admin permission problem)

Open Adobe dreamweaver CS3 (or whatever you installed).... and paste crack file (dreamweaver) here (overwrite the older one).

Go to configuration folder....

Then DocumentTypes...... Open MMDocumentTypes file .......... find php5 (it would be on two places).....

Just write ,phtml after php5 in both of the places........

Now you can check.... it will work fine.... :)

Install Symfony in XAMPP

http://www.seiler.it/installing-symfony-framework.html

Wednesday, 1 June 2011

Check all checkboxes through JQuery on a Checkbox event

 //chkAllSub function calls on sub checkboxes click
//chkAll function calls on main checkbox
//.sub_chk is the class of sub checkboxes
//master is the ID of main checkbox



function chkAllSub()
{
  $(".sub_chk").each(function(){
    var chkboxLength = $("input.sub_chk").length;
    if($("input.sub_chk:checked").length >= chkboxLength)
    {
      $("#master").attr('checked',true);
    }
    else
    {
      $("#master").attr('checked',false);
    }
  })
}
function chkAll()
{
  if($("#master").is(':checked',true))
  {
    $(".sub_chk").attr('checked',true);
  }
  else
  {
    $(".sub_chk").attr('checked',false);
  }
}

Monday, 9 May 2011

Check all checkboxes through JQuery

$(document).ready(function(){
$(".checkall").click( function() {
  $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
})

})

Find any part of string in another string & manipulate accordingly

<?php
$string = 'www.google.com';//string
$ss = strpos($string,'http://');//cheking whether the part of string exist in full string or not
if($ss!==false)//if exists
{
  $string = $string;
}
else
{
  $string = 'http://'.$string;
}
echo $string;//final string.
?>

Friday, 6 May 2011

Regular Expression in MySQL

WHERE phone REGEXP '[(]435[)]';

would return only phone numbers with (435), such as "1(435)555-5555".

GroupConcat in MySql directly gives the output in required format as string

Language is column name and CountryLanguage is table name

English
Hindi
Punjabi
Chinese

SELECT GROUP_CONCAT(Language) As Languages FROM CountryLanguage;

Output will be:

English,Hindi,Punjabi,Chinese

SELECT GROUP_CONCAT(Language SEPARATOR '-') As Languages FROM CountryLanguage;
Output will be:


English-Hindi-Punjabi-Chinese

Wednesday, 4 May 2011

Get data through JSON

//Javascript Code

<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#sample").click(function(){

  $.ajax({
      type:'GET',
      url :'testAjax.php',
      success:function(msg)
      {
        var jvar = eval('(' + msg + ')');
        alert(jvar.a);
        alert(jvar.b);
      }
  })
})
})
</script>

//Sample Div

<div id="sample" style="cursor:pointer;>here</div>


//PHP request page

<?php
$arr = array('a'=>5,'b'=>8);
$encodedVal = json_encode($arr);
echo $encodedVal;
?>

Fibonacci series in PHP

<?php

$first = 0;
$second = 1;
$n = 20; // number of times you want to print the value
print $first.'<br>'; // print the first value
for($i=1;$i<$n;$i++)
{
  $final = $first + $second;
  $first = $second;
  $second = $final;
  print $final.'<br>';
}

?>

Sunday, 1 May 2011

To get the file extension

$filename = Name of the file

function findfileextension($filename)
{
     if(strpos(strrev($filename), ".")===false)
     {
            return "";
     }
     else
     {
         $ipos = strpos(strrev($filename), ".");
         $ext = substr($filename, -1*$ipos);
       
         return $ext;
     }
}

Thursday, 28 April 2011

Extract only numeric value from a string through Regular Expression

$TextVariable = 'Dummy54Da69ta';
$NumericVal = preg_replace("/[^0-9]+/","",$TextVariable);
echo $NumericVal;

Wednesday, 27 April 2011

Disable right click option

<!-- Include JQuery latest file -->

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

Extract image from string

<?php
$contents = 'This is test content and an image tage after that. <img title="Dummy Image" src="http://www.warepin.com/wp-content/uploads/2010/03/sample-proposals-for-computer-hardware.jpg" alt="DummyImage" />
  You will get the image from the string';

$pos = stripos($contents,'<img');
$posimg = stripos($contents, ">", $pos);
$final = substr($contents, $posimg+1);
echo $final; // Total content
$len = strlen($final);

$img = substr($contents, 0, -$len);
echo $img; // The image

?>

Break a long string containing no space

$text is a long string.

$text = "45353453453erfgdvdfbfgbfgbfgb";
$newtext = wordwrap($text, 8, "\n", true);
echo $newtext;

Father of PHP

Rasmos Lerdoff