Wednesday, July 9, 2014

Javascript - Remove Last Comma from a string



Javascript - Remove Last Comma from a string


var str = 'This is a test,          '; 
alert( removeLastComma(str) ); // should remove the last comma

function removeLastComma(strng){        
    var n=strng.lastIndexOf(",");
    var a=strng.substring(0,n) 
    return a;
}

Wednesday, September 25, 2013

PHP - Mobile and Tablet device detection in PHP


Mobile and Tablet device detection in PHP

Solution:

<?php
$tablet_browser = 0;
$mobile_browser = 0;
 
if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $tablet_browser++;
}
 
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android|iemobile)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $mobile_browser++;
}
 
if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
    $mobile_browser++;
}
 
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
$mobile_agents = array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda ','xda-');
 
if (in_array($mobile_ua,$mobile_agents)) {
    $mobile_browser++;
}
 
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'opera mini') > 0) {
    $mobile_browser++;
    //Check for tablets on opera mini alternative headers
    $stock_ua = strtolower(isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])?$_SERVER['HTTP_X_OPERAMINI_PHONE_UA']:(isset($_SERVER['HTTP_DEVICE_STOCK_UA'])?$_SERVER['HTTP_DEVICE_STOCK_UA']:''));
    if (preg_match('/(tablet|ipad|playbook)|(android(?!.*mobile))/i', $stock_ua)) {
      $tablet_browser++;
    }
}
 
if ($tablet_browser > 0) {
   // do something for tablet devices
   print 'is tablet';
}
else if ($mobile_browser > 0) {
   // do something for mobile devices
   print 'is mobile';
}
else {
   // do something for everything else
   print 'is desktop';
}   
 
?>

Friday, March 22, 2013

PHP/MySQL with Google Maps

AJAX - Simple Validation Form


<html>
<head>
<title>JQuery Form Validation</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
  $("#form1").validate({
         debug: false,
   rules: {
    name: "required",
    dropdown: "required",
    email: {
     required: true,
     email: true
    }
   },
   messages: {
    name: "Please enter your good name.",
    email: "Please enter your valid email address.",
    dropdown: "Please select option from dropdown list.",
   },
   submitHandler: function(form) {
  
    $.post('nextstep.php', $("#form1").serialize(), function(data) {
     $('#result').html(data);
    });
   }
  });
 });
</script>
<style>
 label.error { width: 250px; display: inline; color: red;}
</style>
</head>
<body>
<form name="form1" id="form1" action="" method="POST">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" value=""/>
 <br>
    <label for="email" id="email_label">Email</label>
    <input type="text" name="email" id="email" size="30" value=""/>
<br>
 Please Select the City:
<select name="dropdown" id="dropdown">
<option value="">None</option>
<option value="mumbai">Mumbai</option>
<option value="delhi">Delhi</option>
<option value="pune">Pune</option>
</select>
 <br>
 <input type="submit" name="submit" value="Submit">
</form>
<!-- We will output the results from process.php here -->
<div id="result"><div>
</body>
</html>

Friday, February 15, 2013

PHP - URL Encode and Decode Query String

You can Encrypt the Query String value by using the below coding


$link = "http://www.example.com/?item=".urlencode(base64_encode("user-data"));
You can Decrypt the Query String value by using the below coding
urldecode(base64_decode($_REQUEST['item']));

Tuesday, October 30, 2012

JavaScript - Current Date less than Chosen Date


Example:


 var dateField = document.getElementById("txtAppDate").value;
           dateField=dateField.replace("-","/");
              var d=dateField.replace("-","/");        
            var stDate = new Date();
            var enDate = new Date(Date.parse(d));
            var compDate = enDate - stDate;



if(compDate<=0)
                {
                    alert('the entered appointment Date should be greater than todays date');
                    return false;
                }

Sunday, October 7, 2012

SSRS - HTTP 401: Unauthorized With the Reporting Services Web Service


Solution:
You would have to change the reporting services authentication mode to "Basic" from Windows. 

Open RSReportServer.config (by default, C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer) and replace 

<Authentication>
<AuthenticationTypes>
<RSWindowsNTLM/>
</AuthenticationTypes>
<EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>

with following entry -

<AuthenticationTypes>
<RSWindowsBasic/>
</AuthenticationTypes>