Wednesday 17 July 2013

PHP Interview Questions

Q) How the form data is transmitted?

GET:

1) The user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. The GET method sends all the gathered information along as part of the URL.
 
2) In this scenario, form data are restricted to ASCII codes means  only ASCII characters allowed..

3) GET is less secure compared to POST because data sent is part of the URL. So it's saved in browser history and 
server logs in plain-text

4)
form data is in the URL and URL length is restricted. A safe URL length limit is often 2048 characters but varies by browser and web server.

5)
7607 character maximum size is allowed.


POST:


1) The user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute and it to define url.

2) No restrictions. Binary data is also allowed.
3) The POST method transmits the information invisibly to the user.
4) The size of data has no restrictions.
5) 8 Mb max size for the POST method.


Q) Who is the father of HTML?

Tim Berners-Lee  is a British computer scientist, best known as the inventor of the World Wide Web. He is inventor of HTML.

Q) Who is the father of PHP?

Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3

Q) In how many ways we can retrieve the data in the result set of MySQL using PHP?


  • You can do it by 4 Ways


  • 1. mysql_fetch_row.


  • 2. mysql_fetch_array
    3. mysql_fetch_object
    4. mysql_fetch_assoc


    Q) How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com using regular expression of PHP?

    We can extract by

    $found="abc.com";
    preg_match("/^http:\/\/.+@(.+)$/","http://info@abc.com&#8217",$found);
    echo $found[1];

    Q) How to check PHP version ?

    echo phpversion();

    Q) What are the current versions of apache, PHP, and MySQL?

    As of February, 2007 the current versions are
    PHP: p
    hp5.5.1
    MySQL: MySQL 5.5
    Apache: Apache 2.2.4

    Q) What are the different types of errors in PHP?

    1. Notices:
    2. Warnings
    3. Fatal errors

    Q) How to read write and delete file in PHP?

    $m_img = "toltrip.png";
    
    $m_img_path = "/var/www/java/jquery/".$m_img;
    echo file_exists($m_img_path);
    if (file_exists($m_img_path))
    {
         unlink($m_img_path);
    }
    // See if it exists again to be sure it was removed
    if (file_exists($m_img_path))
    {
              echo "Problem deleting " . $m_img_path;
    }
    else
    {
            echo "Successfully deleted " . $m_img_path;
    }
    //For write content in file
    
    $fh = fopen('test.html', 'a');
    fwrite($fh, 'Hello world!');
    fclose($fh)
    


    Q) How to split word in to character in PHP?

     We can split word to seprate in  character 
    $pieces = str_split("piece1");
    print_r($pieces);
    

    Q) What is the value of $b in the following code?

        $a="5 USD";
        $b=10+$a;
        echo $b;



    If the string does not contain any of the characters '.', 'e', or 'E' and the numeric value fits into integer type limits (as defined by PHP_INT_MAX), the string will be evaluated as an integer. In all other cases it will be evaluated as a float.
    The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits.

    Q) What are super global arrays?

    All variables that come into PHP arrive inside one of several special arrays known collectively as the superglobals. They're called superglobal because they are available everywhere in your script, even inside classes and functions.

    $GLOBALS
    $_GET
    $_POST
    $_SESSION
    $_COOKIE
    $_REQUEST
    $_ENV
    $_SERVER



    Guys I will upload more question later.

    No comments:

    Post a Comment