PHP Developer

Sunday, 30 November 2014

Set Limit Or Restrict to Enter Fix Number of words to textbox in php

Set Limit Or Restrict to Enter Fix Number of words to textbox in php

<?php $number_words = 30;?>  //Set Number of words Enter in TextBox

<!--Javascript Code START -->
<script type="text/javascript">
$(function() {
    //set up text length counter
    var number_words = "<?php echo $number_words;?>";
    $('#id_limited_textarea').keyup(function() {
        update_chars_left(number_words, $('#id_limited_textarea')[0], $('#text_chars_left'));
    });
    //and fire it on doc ready, too
    update_chars_left(number_words, $('#id_limited_textarea')[0], $('#text_chars_left'));

});

function update_chars_left(max_len, target_input, display_element) {
   var text_len = target_input.value.length;
   if (text_len >= max_len) {
       target_input.value = target_input.value.substring(0, max_len);        display_element.html("0");
   } else {
       display_element.innerHTML(max_len - text_len);
   }
}
</script>

<!--Javascript Code END -->

Saturday, 22 November 2014

Get Latitude, Longitude and Zip Code (Post Code) of area where website is open or upload in PHP

Get Latitude, Longitude and Zip Code (Post Code) of area where website is open or upload in PHP


<?php
$geoplugin = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );  //For online website use this line

/*  $geoplugin = unserialize( file_get_contents('http://www.geoplugin.net/php.gp) ); */   //On Localhost Use this line

if ( is_numeric($geoplugin['geoplugin_latitude']) && is_numeric($geoplugin['geoplugin_longitude']) ) {

     echo $lat = $geoplugin['geoplugin_latitude'];   //Show Latitude of present Location
     echo $long = $geoplugin['geoplugin_longitude'];
   //Show Latitude of present Location   
    }

    $zipurl = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$long."&sensor=true";
   
    $value = json_decode(file_get_contents($zipurl));
   
    foreach ($value->results as $result) {
        foreach($result->address_components as $addressPart) {
            if((in_array('postal_code', $addressPart->types))) {
                $state = $addressPart->long_name;   //Show Zip Code of present Location
            }
        }
    }
    echo $present_zipcde = $state;  
?>


Note :-  Add this code anywhere in website where you want to get or show Latitude, Longitude and Post Code