Thursday, December 22, 2011

Twitter call back function


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8">
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
 js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
 return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
 }(document, "script", "twitter-wjs"));
 twttr.ready(function (twttr) {
 twttr.events.bind('tweet', function (event) {
alert('testing');
    });
 });
var myurl = "http://www.google.com";
var mytext = "Text";
var url = "https://twitter.com/intent/tweet" + 
 "?url=" + encodeURIComponent(myurl) + 
 "&text=" + encodeURIComponent(mytext);
 document.getElementById("shareLink").href = url; 
 </script>
</head>
<body>
<a id="shareLink" href="https://twitter.com/intent/tweet">Tweet</a>
</body>
</html>
OUTPUT:










Click here for twitter callback test

Tuesday, November 22, 2011

Firefox is working but Chrome and IE aren’t


This is a proxy error usually caused by a virus.
Load internet explorer then on the Tools menu in Internet Explorer, click Internet Options, click the Connections tab, and then click LAN Settings. Then there will be two check boxes that are checked. First uncheck the second/bottom box then the first/top box. Then Click OK. Then Both will be fixed as Chrome uses IE configs.

Display state name from 2 letter state php script


<?php
$state = array();
  $state['AL']='ALABAMA';
  $state['AL']='ALASKA';
  $state['AS']='AMERICAN SAMOA';
  $state['AZ']='ARIZONA';
  $state['AR']='ARKANSAS';
  $state['CA']='CALIFORNIA';
  $state['CO']='COLORADO';
  $state['CT']='CONNECTICUT';
  $state['DE']='DELAWARE';
  $state['DC']='DISTRICT OF COLUMBIA';
  $state['FM']='FEDERATED STATES OF MICRONESIA';
  $state['FL']='FLORIDA';
  $state['GA']='GEORGIA';
  $state['GU']='GUAM';
  $state['HI']='HAWAII';
  $state['ID']='IDAHO';
  $state['IL']='ILLINOIS';
  $state['IN']='INDIANA';
  $state['IA']='IOWA';
  $state['KS']='KANSAS';
  $state['KY']='KENTUCKY';
  $state['LA']='LOUISIANA';
  $state['ME']='MAINE';
  $state['MH']='MARSHALL ISLANDS';
  $state['MD']='MARYLAND';
  $state['MA']='MASSACHUSETTS';
  $state['MI']='MICHIGAN';
  $state['MN']='MINNESOTA';
  $state['MS']='MISSISSIPPI';
  $state['MO']='MISSOURI';
  $state['MT']='MONTANA';
  $state['NE']='NEBRASKA';
  $state['NV']='NEVADA';
  $state['NH']='NEW HAMPSHIRE';
  $state['NJ']='NEW JERSEY';
  $state['NM']='NEW MEXICO';
  $state['NY']='NEW YORK';
  $state['NC']='NORTH CAROLINA';
  $state['ND']='NORTH DAKOTA';
  $state['MP']='NORTHERN MARIANA ISLANDS';
  $state['OH']='OHIO';
  $state['OK']='OKLAHOMA';
  $state['OR']='OREGON';
  $state['PW']='PALAU';
  $state['PA']='PENNSYLVANIA';
  $state['PR']='PUERTO RICO';
  $state['RI']='RHODE ISLAND';
  $state['SC']='SOUTH CAROLINA';
  $state['SD']='SOUTH DAKOTA';
  $state['TN']='TENNESSEE';
  $state['TX']='TEXAS';
  $state['UT']='UTAH';
  $state['VT']='VERMONT';
  $state['VI']='VIRGIN ISLANDS';
  $state['VA']='VIRGINIA';
  $state['WA']='WASHINGTON';
  $state['wv']='WEST VIRGINIA';
  $state['WI']='WISCONSIN';
  $state['WY']='WYOMING';
  //canadian provinces
  $state['AB']='ALBERTA';
  $state['BC']='BRITISH COLUMBIA';
  $state['MB']='MANITOBA';
  $state['NB']='NEW BRUNSWICK';
  $state['NL']='LABRADOR';
  $state['NL']='NEWFOUNDLAND';
  $state['NT']='NORTHWEST TERRITORIES';
  $state['NS']='NOVA SCOTIA';
  $state['NU']='NUNAVUT';
  $state['ON']='ONTARIO';
  $state['PE']='PRINCE EDWARD ISLAND';
  $state['QC']='QUEBEC';
  $state['SK']='SASKATCHEWAN';
  $state['YT']='YUKON';
                $sc = 'CA'; //change CA to the variable
                $statez = $state[''.$sc.'']; //can do strtolower on statez if need be
?>

Thursday, November 17, 2011

Get twitter status using PHP



<?
echo get_status('username');


function get_status($twitter_id, $hyperlinks = true) {
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, \"http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1\");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $src = curl_exec($c);
    curl_close($c);
    preg_match(\'/<text>(.*)<\\/text>/\', $src, $m);
    $status = htmlentities($m[1]);
    if( $hyperlinks ) $status = ereg_replace(\"[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\", \'<a href=\"%5C%22%5C%5C0%5C%22\">\\\\0</a>\', $status);
    return($status);
}
?>

Thursday, November 3, 2011

What is Main Difference between PHP4 and PHP5?


You most likely know that PHP 5 is destined for OOP, but it appears that usual programming can be used too. Furthermore, OOP is used in PHP4 as well, with the difference that in PHP5 things are a little more evaluated. This means that in PHP4 safety modes for classes (public, private) are not accepted. In PHP4 the objects are a kind of structures which accept objects and functions as well, according to OOP. In PHP4 they are useful as well.
If you are used to working with PHP4 you can use PHP5 with no problems because the differences are not important and the changes were made so that programmers would not be confused. An example would be class builders which, in PHP4 were functions within the classes bearing the same name as the class. In PHP5 it is firstly checked if there is a function (method) __construct (). If it does not exist, check if there is a function (method) which has the same name as the class. This means that even if you are not aware of the latest news in the domain of PHP5, your scripts will function without any problem.

PHP 5.4 beta2 released

The PHP development team is proud to announce the second beta release of PHP 5.4. PHP 5.4 includes new language features and removes several legacy (deprecated) behaviours. Windows binaries can be downloaded from the Windows QA site. THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION! Please help us to identify bugs by testing new features and looking for unintended backward compatibility breaks, so we can fix the problems and fully document intended changes before PHP 5.4.0 is released. Report findings to the QA mailing list and/or the PHP bug tracker. This release includes numerous bug fixes and improvements since the first beta release. Read the NEWS file for a complete list of changes.

Enable Textbox after selecting the checkbox

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
function enableMe(fld)
{
eval('window.document.formx.'+fld+'.disabled = !window.document.formx.'+fld+'CB'+'.checked');
}
</script>
</head>
<body>
<form name="formx" action="" method="post" >
  <table>
    <tr>
      <td><input type="text" disabled="disabled" name="firstbox" value="First box" >
      </td>
      <td width="235"><input type="checkbox" value="1" name="firstboxCB" onClick="enableMe('firstbox');" />
      </td>
    </tr>
    <tr>
      <td><input type="text" disabled="disabled" name="secondbox" value="Second box" >
      </td>
      <td width="235"><input type="checkbox" value="1" name="secondboxCB" onClick="enableMe('secondbox');" />
      </td>
    </tr>
  </table>
</form>
</body>
</html>

Preview:



Using Radio buttons Display specified number of file uploads

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function show_up(x){


  if(x > 5){
     document.getElementById('extra').style.display = 'table-cell';
document.getElementById('extras').style.display = 'none';

  }else{
     document.getElementById('extras').style.display = 'table-cell';
document.getElementById('extra').style.display = 'none';

  }

}
</script>
<style>
  .hide{
     display:none;
  }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form name="form" method="post">
  <input name="showups" type="radio" value="0" onclick="show_up(5);"/>
  <label for="show5">Show 5 upload fields</label>
  <input name="showups" id="show10" type="radio" value="1" onclick="show_up(10);"/>
  <label for="show10">Show 10 upload fields</label>
  <div id = "extra" class="show" style="display:none">
    <table>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
    </table>
  </div>
  <div id = "extras" class="show" style="display:none">
    <table>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
      <tr>
        <td><input type="file" name="upload[]" />
        </td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>



Preview:







Wednesday, October 12, 2011

Crop any Image into square


you can crop either square/rectangular image into square image. here is the code.


<?php

function square_crop($src_image, $dest_image, $thumb_size = 150, $jpg_quality = 90) {

    // Get dimensions of existing image
    $image = getimagesize($src_image);

    // Check for valid dimensions
    if( $image[0] <= 0 || $image[1] <= 0 ) return false;

    // Determine format from MIME-Type
    $image['format'] = strtolower(preg_replace('/^.*?\//', '', $image['mime']));

    // Import image
    switch( $image['format'] ) {
        case 'jpg':
        case 'jpeg':
            $image_data = imagecreatefromjpeg($src_image);
        break;
        case 'png':
            $image_data = imagecreatefrompng($src_image);
        break;
        case 'gif':
            $image_data = imagecreatefromgif($src_image);
        break;
        default:
            // Unsupported format
            return false;
        break;
    }

    // Verify import
    if( $image_data == false ) return false;

    // Calculate measurements
    if( $image[0] < $image[1] ) {
        // For landscape images
        $x_offset = ($image[0] - $image[1]) / 2;
        $y_offset = 0;
        $square_size = $image[0] - ($x_offset * 2);
    } else {
        // For portrait and square images
        $x_offset = 0;
        $y_offset = ($image[1] - $image[0]) / 2;
        $square_size = $image[1] - ($y_offset * 2);
    }

    // Resize and crop
    $canvas = imagecreatetruecolor($thumb_size, $thumb_size);
    if( imagecopyresampled(
        $canvas,
        $image_data,
        0,
        0,
        $x_offset,
        $y_offset,
        $thumb_size,
        $thumb_size,
        $square_size,
        $square_size
    )) {

        // Create thumbnail
        switch( strtolower(preg_replace('/^.*\./', '', $dest_image)) ) {
            case 'jpg':
            case 'jpeg':
                return imagejpeg($canvas, $dest_image, $jpg_quality);
            break;
            case 'png':
                return imagepng($canvas, $dest_image);
            break;
            case 'gif':
                return imagegif($canvas, $dest_image);
            break;
            default:
                // Unsupported format
                return false;
            break;
        }

    } else {
        return false;
    }

}
square_crop('source image path', 'Destination image path');




?>

Thursday, July 21, 2011

EIGHT LESSONS: Google map on popup window

EIGHT LESSONS: Google map on popup window

Google map on popup window


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Find latitude and longitude with Google Maps</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=Goolge api"
      type="text/javascript"></script>
<script type="text/javascript">
 function load() {
   if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(48.89364,2.33739);
        map.setCenter(center, 15);
   geocoder = new GClientGeocoder();
        var marker = new GMarker(center, {draggable: true});
        map.addOverlay(marker);
//alert(center.lat().toFixed(5));
        document.formx.latitude.value = center.lat().toFixed(5);
        document.formx.langitude.value = center.lng().toFixed(5);
 GEvent.addListener(marker, "dragend", function() {
       var point = marker.getPoint();
     map.panTo(point);
       document.formx.latitude.value = point.lat().toFixed(5);
       document.formx.langitude.value = point.lng().toFixed(5);
   });
 GEvent.addListener(map, "moveend", function() {
 map.clearOverlays();
    var center = map.getCenter();
 var marker = new GMarker(center, {draggable: true});
 map.addOverlay(marker);
 document.formx.latitude.value = center.lat().toFixed(5);
  document.formx.langitude.value = center.lng().toFixed(5);
GEvent.addListener(marker, "dragend", function() {
      var point =marker.getPoint();
    map.panTo(point);
      document.formx.latitude.value = point.lat().toFixed(5);
    document.formx.langitude.value = point.lng().toFixed(5);


        });

        });

      }
    }

  function showAddress(address) {
  var map = new GMap2(document.getElementById("map"));
       map.addControl(new GSmallMapControl());
       map.addControl(new GMapTypeControl());
       if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
 document.formx.latitude.value = point.lat().toFixed(5);
  document.formx.langitude.value = point.lng().toFixed(5);

map.clearOverlays()
map.setCenter(point, 14);
   var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);

GEvent.addListener(marker, "dragend", function() {
      var pt = marker.getPoint();
    map.panTo(pt);
      document.formx.latitude.value = pt.lat().toFixed(5);
    document.formx.langitude.value= pt.lng().toFixed(5);
 });
GEvent.addListener(map, "moveend", function() {
 map.clearOverlays();
    var center = map.getCenter();
 var marker = new GMarker(center, {draggable: true});
 map.addOverlay(marker);
 document.formx.latitude.value = center.lat().toFixed(5);
  document.formx.langitude.value= center.lng().toFixed(5);
   
GEvent.addListener(marker, "dragend", function() {
     var pt = marker.getPoint();
   map.panTo(pt);
    document.formx.latitude.value = pt.lat().toFixed(5);
  document.formx.langitude.value = pt.lng().toFixed(5);

        });

        });

            }
          }
        );
      }
    }
    </script>
<style type="text/css">
.popup_table tr td{
border:1px solid #ccc;
background-color:#fff;
}</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>

$(document).ready(function() {

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();

//Get the A tag
var id = $(this).attr('href');

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
      //Set the popup window to center
$(id).css('top',  winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);

$(window).resize(function(){
location.reload();
});
load();
});

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});

</script>
<style>


#mask {
  position:absolute;
  left:0;
  top:0;
  z-index:9000;

  display:none;
}

#boxes .window {
  position:absolute;
  left:0;
  top:0;
  width:500px;
  height:300px;
  display:none;
  z-index:9999;
  padding:20px;
}

#boxes #dialog {
  width:500px;
  height:350px;
  padding:10px;
  background-color:#ffffff;
}
</style>
<script type="text/javascript">
function show_points(){

var lat=document.formx.latitude.value;
var lng=document.formx.langitude.value;

document.getElementById("lati").value=lat;
document.getElementById("lang").value=lng;
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<ul>
  <li><a href="#dialog" name="modal" id="showMap">Simple Window Modal</a></li>
</ul>
<table>
  <tr>
    <td><input type="text" name="lat" id="lati" value="" /></td>
    <td><input type="text" name="lang" id="lang" value="" /></td>
  </tr>
</table>
<div id="boxes">
  <div id="dialog" class="window"> Simple Modal Window | <a href="#"class="close"/>Close it</a>
    <form name="formx" action="#" onsubmit="showAddress(this.address.value); return false">
      <table width="50%" border="0" cellspacing="0" cellpadding="5" style="border:1px solid #eddfaf; background-color:#F9F4E2;">
        <tr>
          <td><table width="100%" cellpadding="3" cellspacing="0"  bgcolor="#eddfaf">
              <tr>
                <td><input type="text" size="50" name="address" value="3 cit&eacute; Nollez Paris France" /></td>
                <td><input type="submit" value="Search!" /></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td><table  width="420" cellpadding="2" cellspacing="0"  bgcolor="#eddfaf">
              <tr>
                <td colspan="2"></td>
              </tr>
              <tr>
                <td align="center"><b>Latitude</b></td>
                <td align="center"><b>Longitude</b></td>
              </tr>
              <tr>
                <td><input type="text" name="latitude" id="lat" /></td>
                <td><input type="text" name="langitude" id="lng" /></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td><div align="center" id="map" style="width: 480px; height: 200px"><br/>
            </div>
            <a href="#" onclick="show_points();">Like it</a> </td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>

OUTPUT:









Simple Modal Window | Close it
Latitude Longitude


Like it


EIGHT LESSONS: Import CSV Data into Mysql

EIGHT LESSONS: Import CSV Data into Mysql

Import CSV Data into Mysql

Here We are converting CSV data into Mysql.
example: we have name,email,phone now we are importing .csv data into mysql
below is the code for this
<?
   if(isset($_POST['submit']))
    {

         $fname = $_FILES['sel_file']['name'];
     
         $chk_ext = explode(".",$fname);
     
         if(strtolower($chk_ext[1]) == "csv")
         {
     
             $filename = $_FILES['sel_file']['tmp_name'];
             $handle = fopen($filename, "r");
     
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
             {
                $sql = "INSERT into user(name,email,phone) values('$data[0]','$data[1]','$data[2]')";
echo $sql;
               // mysql_query($sql) or die(mysql_error());
             }exit;
     
             fclose($handle);
             echo "Successfully Imported";
         }
         else
         {
             echo "Invalid File";
         }
    }
?>
    <form action='' method='post' enctype="multipart/form-data">

        Import File : <input type='file' name='sel_file' size='20'>
        <input type='submit' name='submit' value='submit'>

    </form>
OUTPUT:


Import File :


How To Convert Excel sheet into CSV

We can convert with out using any code.

This method is the most easiest and in fact doesn’t require any tool at all.
 Just head over to Google Docs and login with your Google account.

1.Click New and select Spreadsheet.
This will open a new window where you will find the spreadsheet.

2.Now click File and then select Import.
You can import the following format, .xls, .xlsx, .ods, .csv, and .txt. Click choose file and select the Excel Spreadsheet you want to convert. Once importing is done, hit Open Now link.

Tuesday, July 19, 2011

Clean variable using PHP

<?
function clean($value) {

       // If magic quotes not turned on add slashes.
       if(!get_magic_quotes_gpc())

       // Adds the slashes.
       { $value = addslashes($value); }

       // Strip any tags from the value.
       $value = strip_tags($value);

       // Return the value out of the function.
       return $value;

}
$sample = "<a href='test.php'><strong>test</strong></a>";
$sample = clean($sample);
echo $sample;
?>
Out Put: test

Block censored words using php

does this string contain any ****** ****** ****** ****** ******
<?
// Array containing profane words
$arrProfanities = array('these', 'are', 'the', 'words', 'I', 'want', 'to', 'filter');

// String containing content you want to filter for profane words
$strContent = 'does this string contain any words I want to filter';

// This will replace all the words from the array that are matched in the string with [censored]
$strContent = str_replace($arrProfanities, '******', $strContent);
echo $strContent;
// Output would be:
// $strContent = 'does this string contain any [censored] [censored] [censored] [censored] [censored]?';
?>

Add Multiple Images with Captions

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload Multiple images with Captions</title>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">

(function (a) {
  a.fn.relCopy = function (f) {
    var b = jQuery.extend({
      excludeSelector: ".exclude",
      emptySelector: ".empty",
      copyClass: "copy",
      append: "",
      clearInputs: true,
      limit: 0
    }, f);
    b.limit = parseInt(b.limit);
    this.each(function () {
      a(this).click(function () {
        var e = a(this).attr("rel"),
            d = a(e).length;
        if (b.limit != 0 && d >= b.limit) return false;
        var c = a(e + ":first"),
            g = a(c).parent();
        c = a(c).clone(true).addClass(b.copyClass + d).append(b.append);
        b.excludeSelector && a(c).find(b.excludeSelector).remove();
        b.emptySelector && a(c).find(b.emptySelector).empty();
        if (a(c).attr("id")) {
          var h = a(c).attr("id") + (d + 1);
          a(c).attr("id", h)
        }
        a(c).find("[id]").each(function () {
          var i = a(this).attr("id") + (d + 1);
          a(this).attr("id", i)
        });
        b.clearInputs && a(c).find(":input").each(function () {
          switch (a(this).attr("type")) {
          case "button":
            break;
          case "reset":
            break;
          case "submit":
            break;
          case "checkbox":
            a(this).attr("checked", "");
            break;
          default:
            a(this).val("")
          }
        });
        a(g).find(e + ":last").after(c);
        return false
      })
    });
    return this
  }
})(jQuery);

</script>
<script type="text/javascript">
$(function(){
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';

$('a.add').relCopy({ append: removeLink});
});
</script>
</head>

<body>
<form method="post" action="clonesubmit.php">
<p class="clone"> <input type="text" name="hobby[]" class='input'/>
<input name="images[]" type="file"/>
</p>
<p><a href="#" class="add" rel=".clone">Add More</a></p>
<input type="submit" value=" Submit " />
</form>
</body>
</html>

Download reCopy.js

OUTPUT:








Add More


Saturday, January 29, 2011

Auto check selectbox display total using php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jay Rumsey | http://www.nova.edu/~rumsey/ */

function UpdateCost() {
  var sum = 0;
  var gn, elem;
  for (i=0; i<5; i++) {
    gn = 'game'+i;
    elem = document.getElementById(gn);
    if (elem.checked == true) { sum += Number(elem.value); }
  }
  document.getElementById('totalcost').value = sum.toFixed(2);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<input type="checkbox" id='game0' value="9.99"  onclick="UpdateCost()">Game 1 ( 9.99)<br>
<input type="checkbox" id='game1' value="19.99" onclick="UpdateCost()">Game 2 (19.99)<br>
<input type="checkbox" id='game2' value="27.50" onclick="UpdateCost()">Game 3 (27.50)<br>
<input type="checkbox" id='game3' value="45.65" onclick="UpdateCost()">Game 4 (45.65)<br>
<input type="checkbox" id='game4' value="87.20" onclick="UpdateCost()">Game 5 (87.20)<br>
<input type="text" id="totalcost" value="">
</body>
</html>

OUTPUT:

Game 1 ( 9.99) Game 2 (19.99) Game 3 (27.50) Game 4 (45.65) Game 5 (87.20)

array multisort using php

function multisort($array, $sort_by) {
    foreach ($array as $key =>$value) {
$evalstring = '';
foreach ($sort_by as $sort_field) {
$tmp[$sort_field][$key] = $value[$sort_field];
$evalstring .= '$tmp[\'' . $sort_field . '\'], ';
}
}
$evalstring .= '$array';
$evalstring = 'array_multisort(' . $evalstring . ');';
eval($evalstring);

return $array;
}

$test = array(
array( 'a' => '1', 'b' => '3'),
array( 'a' => '2', 'b' => '1'),
array( 'a' => '1', 'b' => '1'));

echo 'Unsorted: ';
print_r($test);

$result = multisort( $test , array('a','b') );

echo 'Sorted: ';
print_r($result);
?>

OUTPUT:

Unsorted: Array ( [0] => Array ( [a] => 1 [b] => 3 ) [1] => Array ( [a] => 2 [b] => 1 ) [2] => Array ( [a] => 1 [b] => 1 ) )

Sorted: Array ( [0] => Array ( [a] => 1 [b] => 1 ) [1] => Array ( [a] => 1 [b] => 3 ) [2] => Array ( [a] => 2 [b] => 1 ) ) 

Display Live stocks using php

<?
$symbols=array('AAPL', 'GOOG', 'RIMM', 'MSFT');
echo stock_ticker($symbols,"d0d0d0","black","00c000");exit;
function stock_ticker ($symbols, $background_color, $stock_color, $price_color)
{
  sort($symbols);
 
  $return = '<div align="center">
  <marquee bgcolor="#dddddd" loop="10" behaviour="scroll">';
 
  foreach ($symbols as $symbol) {
    $data = file_get_contents("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv");
   
    $values = explode(",", $data);
    $lasttrade = $values[1];
    $change = $values[4];
   
    $return .= "<font color=\"#000000\">$symbol</font> &nbsp;";
    $return .= "<font color=\"#0000bb\">$lasttrade</font> &nbsp;";
    if ($change<0)
      $return .= "<font color=\"#ff0000\">$change</font> &nbsp;";
    else
      $return .= "<font color=\"#00bb00\">$change</font> &nbsp;";
    $return .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  }
 
  $return .= '</marquee>
  </div>';
 
  return $return;
}
?>

OUTPUT:
AAPL  336.10  -7.11        GOOG  600.99  -15.80        MSFT  27.751  -1.119        RIMM  60.15  -1.83        




Display results in column wise using php

<?
 
$states_array=array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshir","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","Washington DC","West Virginia","Wisconsin","Wyoming");
$result_array=$states_array;
$noofrows = 10;
$noofcols = ( count($states_array)%5 == 0) ? count($states_array)/5 : ( count($states_array)/5 + 1);
$tabledata = "<table >";
for ( $k = 0; $k < $noofrows; $k++ ) {
    $tabledata .= "<tr>";
    for ( $j = 0; $j < $noofcols; $j++ ) {
        $array_index = $k + ($noofrows * $j );
        $tabledata .= "<td>";
        $tabledata .= <<<EOD
        <a href=referecne_page.php?stateid=$result_array[$array_index] class=links>$result_array[$array_index]
EOD;
        $tabledata .= "</td>";
    }
    $tabledata .= "</tr>";
}
$tabledata .= "</table>";
echo $tabledata;

?>
OUTPUT:
AlabamaHawaiiMassachusettsNew MexicoSouth CarolinaWisconsin
AlaskaIdahoMichiganNew YorkSouth DakotaWyoming
ArizonaIllinoisMinnesotaNorth CarolinaTennessee
ArkansasIndianaMississippiNorth DakotaTexas
CaliforniaIowaMissouriOhioUtah
ColoradoKansasMontanaOklahomaVermont
ConnecticutKentuckyNebraskaOregonVirginia
DelawareLouisianaNevadaPennsylvaniaWashington
FloridaMaineNew HampshirPuerto RicoWashington DC
GeorgiaMarylandNew JerseyRhode IslandWest Virginia