Monday, September 27, 2010

Date Validation using Javascript

Here is the validation for date using javascript.

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){  
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){  
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31;
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
        if (i==2){this[i] = 29;}
   }
   return this;
}

function isDate(dtStr){
    var daysInMonth = DaysArray(12);
    var pos1=dtStr.indexOf(dtCh);
    var pos2=dtStr.indexOf(dtCh,pos1+1);
    var strMonth=dtStr.substring(0,pos1);
    var strDay=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    strYr=strYear;
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
    }
    month=parseInt(strMonth);
    day=parseInt(strDay);
    year=parseInt(strYr);
    if (pos1==-1 || pos2==-1){
        alert("The date format should be : mm/dd/yyyy");
        return false;
    }
    if (strMonth.length<1 || month<1 || month>12){
        alert("Please enter a valid month");
        document.form1.month.focus();
        return false;
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter a valid day");
        document.form1.day.focus();
        return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
        return false;
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        alert("Please enter a valid date");
        return false;
    }
    return true;
}

To check the given string is a Date or not, the date format should be checked as shown below.

var dt = document.form1.month.value +'/' +document.form1.day.value +'/'+ document.form1.year.value;
    if (isDate(dt)==false){
        return false;
    }

The date format to be passed is MM/DD/YYYY.

     

Sunday, September 26, 2010

Rewrite condition for domain.com to www.domain.com using HTACCESS

Redirecting from domain.com to www.domain.com is mostly helpful as part of SEO. The rule for rewriting the site is shown below.

rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Just change the domain name to your site name to use the rewrite rule.

  

Sunday, September 5, 2010

Maryada Ramana MP3 Ringtone

The latest mp3 background music from Maryada Ramana. Download it

Click Here to Download the ringtone.

   


Friday, September 3, 2010

Get the Meta Content using Javascript

Here is the code for retrieving the Meta Keywords, Description using Javascript.

var destination = window.location.href;
var meta_title = '',meta_description = '';
       var meta = document.getElementsByTagName("meta");
       for( var x in meta )
       {
               if(/^title$/i.test(meta[x]["name"]))
                       meta_title = meta[x]["content"];
               if(/^description$/i.test(meta[x]["name"]))
                       meta_description = meta[x]["content"];
       }

Wednesday, September 1, 2010

PHP Interview Questions and Answers

Here are some of the PHP interview Questions with answers which may help you.

1. What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?
Answer: On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser's address field. Data submitted by the POST method will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.



2. Who is the father of php and explain the changes in php versions?
Answer:  Rasmus Lerdorf for version changes go to http://php.net/
Marco Tabini is the founder and publisher of php|architect
.

3. How can we submit from without a submit button?
Answer: We can use a simple JavaScript code linked to an event trigger of any form field.
In the JavaScript code, we can call the document.form.submit() function to submit the form.


 4. How many ways we can retrieve the date in result set of mysql Using php?
Answer: As individual objects so single record or as a set or arrays.

5. What is the difference between mysql_fetch_object and mysql_fetch_array?
Answer:  MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

6. What is the difference between $message and $$message?
Answer: They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

7. How can we extract string 'abc.com ' from a string 'http://info@a...' using regular _expression of php?
Answer: We can use the preg_match() function with "/.*@(.*)$/" as
the regular expression pattern. For example:
preg_match("/.*@(.*)$/","http://info@abc.com",$data);
echo $data[1];


8. How can we create a database using php and mysql?
Answer: PHP: mysql_create_db()
Mysql: create database;


9. What are the differences between require and include, include_once?
Answer: File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

10. Can we use include ("abc.php") two times in a php page "makeit.php"?
Answer: Yes we can include..

11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following
syntax: create table employee(eno int(2),ename varchar(10)) ?
Answer: Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. InnoDB
5. ISAM
6. BDB
MyISAM is the default storage engine as of MySQL 3.23
.

12. Functions in IMAP, POP3 AND LDAP?
Answer:  Please visit:
http://fi2.php.net/imap
http://uk2.php.net/ldap


13. How can I execute a php script using command line?
Answer: Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

14. Suppose your ZEND engine supports the mode <? ?> Then how can u configure your php ZEND engine to support <?php ?> mode ?
Answer: If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only <?php ?> mode.

15. Shopping cart online validation i.e. how can we configure the paypals?

16. What is meant by nl2br()?
Answer: nl2br -- Inserts HTML line breaks before all newlines in a string
string nl2br (string); Returns string with '<br />' inserted before all newlines.
For example: echo nl2br("god bless\n you") will output "god bless
\n you" to your browser.


More Interview Questions, Download the document, Click Here for PHP interview Question

For Free Download,Click Here