PHP MCQ Number 01298

PHP MCQ Set 1

1. Before you can start processing images with PHP, you must first add the ability to upload images to your administrative form on ________
a) .htaccess
b) function.inc.php
c) index.php
d) admin.php

Answer

Answer: d [Reason:] To do this, you’ need to add a file upload input to your administrative form.

2. When you’re uploading files you need to set the enctype of the form to __________
a) text
b) text/file
c) multipart/form-data
d) multimedia/form-data

Answer

Answer: c [Reason:] Set the enctype of the form to multipart/form-data, which can accept files and standard form values.

3. To check whether a file was uploaded, you look in the _______ superglobal array.
a) $_FILES
b) $_DOCS
c) $_DOCUMENTS
d) $_FOLDERS

Answer

Answer: a [Reason:] Whenever a file is uploaded via an HTML form, that file is stored in temporary memory and information about the file is passed in the $_FILES superglobal.

4. To make the ImageHandler class portable you should create a separate file for it called __________
a) imagehandler.inc.php
b) images.inc.php
c) handler.inc.php
d) imghandler.inc.php

Answer

Answer: b [Reason:] You save this file in the inc folder (full path: /xampp/htdocs/simple_blog/inc/images.inc.php).

5. DocBlocks are indicated by opening a comment using _________
a) /*
b) //*
c) /**
d) /*/

Answer

Answer: c [Reason:] This is a special comment that provides information about a class, property, or method.

6. To process the file, you need to break the array from $_FILES into individual values. You can do this using the ________ function.
a) divide()
b) list()
c) break()
d) indi()

Answer

Answer:b [Reason:] The list() function allows you to create named variables for each array index as a comma-separated list.

7. Before you try to process the file, you need to make sure that your $err value is equivalent to _________
a) UPLOAD_ERR_OK
b) UPLOAD_NO_ERR
c) UPLOAD_ERR_NO_OK
d) UPLOAD_ERR

Answer

Answer: a [Reason:] When you’re dealing with files uploaded through an HTML form, you have access to a special constant called UPLOAD_ERR_OK that tells you whether a file uploaded successfully.

8. You use the $_SERVER superglobal and your _______ property to create your path to check.
a) $load_dir
b) $load
c) $save
d) $save_dir

Answer

Answer: d [Reason:] // Determines the path to check
$path = $_SERVER[‘DOCUMENT_ROOT’] . $this->save_dir;

9. Which function do you have to use to check whether the $path you’ve stored exists?
a) path_dir()
b) path()
c) is_dir()
d) path_dir()

Answer

Answer: c [Reason:] If the path exists, is_dir() returns TRUE; otherwise, it returns FALSE.

10. Which one of the following is true about the following line – $obj = new ImageHandler(‘/images/’, array(400, 300));
a) This snippet sets the maximum dimensions allowed to 400 pixels wide by 300 pixels high
b) This snippet sets the minimum dimensions allowed to 300 pixels wide by 400 pixels high
c) This snippet sets the minimum dimensions allowed to 400 pixels wide by 300 pixels high
d) This snippet sets the maximum dimensions allowed to 300 pixels wide by 400 pixels high

Answer

Answer: a [Reason:] If you needed to change the size of your images, you can change the dimensions using the above instantiation of ImageHandler

PHP MCQ Set 2

1. Which one of the following PHP functions can be used to build a function that accepts any number of arguments?
a) func_get_argv()
b) func_get_argc()
c) get_argv()
d) get_argc()

Answer

Answer: b [Reason:] Here is an example-

  1. function foo()
  2. {
  3.     $args = func_get_args();
  4.     foreach ($args as $k => $v)
  5.     {  
  6.        echo "arg".($k+1).": $vn";  
  7.     }
  8. }
  9. foo();
  10. /* will print nothing */
  11.  
  12. foo("Hello");
  13. /* will print Hello */
  14.  
  15. foo("Hello","World","Bye");
  16. /* will print Hello World Bye */

2. Which one of the following PHP functions can be used to find files?
a) glob()
b) file()
c) fold()
d) get_file()

Answer

Answer: a [Reason:] Here is an example-

  1. // get all php files AND txt files  
  2.     $files = glob('*.{php,txt}', GLOB_BRACE);  
  3.     print_r($files);  
  4.     /* output looks like: 
  5.     Array 
  6.     ( 
  7.         [0] => phptest.php 
  8.         [1] => pi.php 
  9.         [2] => post_output.php
  10.         .
  11.         .
  12.         .
  13.     )

3. Which of the following PHP functions can be used to get the current memory usage?
a) get_usage()
b) get_peak_usage()
c) get_memory_usage()
d) get_memory_peak_usage()

Answer

Answer: c [Reason:] We can use the memory_get_usage() function, and to get the highest amount of memory used at any point, we can use the memory_get_peak_usage() function.

4. Which of the following PHP functions can be used for generating unique id’s?
a) uniqueid()
b) id()
c) md5()
d) mdid()

Answer

Answer: a [Reason:] Many people use the md5() function for this, even though it’s not exactly meant for this purpose. uniqueid() is the function that is to be used.

5. Which one of the following functions can be used to compress a string?
a) zip_compress()
b) zip()
c) compress()
d) gzcompress()

Answer

Answer: d [Reason:] We will be able to achieve almost 50% size reduction using this function. The gzuncompress() function is used to uncompress the string.

6. What will be the output of the following PHP code?

  1.     <?php
  2.     echo "chr(52)";
  3.     ?>

a) 1
b) 2
c) 3
d) 4

Answer

Answer: d [Reason:] The chr() function returns a character from the specified ASCII value. Since the ASCII value of 4 is 52, thus 4 was displayed.

7. What will be the output of the following PHP code?

  1.     <?php
  2.     echo ord ("hi");
  3.     ?>

a) 106
b) 103
c) 104
d) 209

Answer

Answer: c [Reason:] The ord() function returns the ASCII value of the first character of a string. The ASCII value of h is 104, thus 104 was displayed.

8. What will be the output of the following PHP code?

  1.     <?php
  2.     $str = "Hello World"
  3.     echo wordwrap($str,5,"<br>n");    
  4.     ?>

a) Hello World
b) Hello
World
c) Hell
o wo
rld
d) World

Answer

Answer: b [Reason:] The wordwrap() function wraps a string into new lines when it reaches a specific length.

9. What will be the output of the following PHP code?

  1.     <?php
  2.     echo ucwords("i love my country");
  3.     ?>

a) I love my country
b) i love my Country
c) I love my Country
d) I Love My Country

Answer

Answer: d [Reason:] The ucwords() function converts the first character of each word in a string to uppercase.

10. What will be the output of the following PHP code?

  1.     <?php
  2.     echo lcfirst("welcome to India");
  3.     ?>

a) welcome to India
b) welcome to india
c) Welcome to India
d) Welcome to india

Answer

Answer: a [Reason:] The lcfirst() function converts the first character of a string to lowercase.

PHP MCQ Set 3

1. What will be the output of the following PHP code?

  1.     <?php
  2.     $number = array(0,1,two,three,four,5);
  3.     $num = preg_grep("/[0-5]/", $number);
  4.     print_r($num);
  5.     ?>

a) Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)
b) Array([2]=>two [3]=>three [4]=>four)
c) Array([1]=> 1)
d) Array([0]=>0 [1]=>1 [5]=>5)

Answer

Answer: d [Reason:] The preg_grep function is used to search an array for specific patterns and then return a new array based on that filtering.

2. What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?
a) Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)
b) Array([2]=>two [3]=>three [4]=>four)
c) Array([1]=> 1)
d) Array([0]=>0 [5]=>5)

Answer

Answer: b [Reason:] When we include PREG_GREP_INVERT, this will invert our data, so instead of outputting numbers it will output our non-numeric values.

3. Which one of the following functions is used to search a string?
a) preg_match
b) preg_search
c) preg_find
d) preg_found

Answer

Answer: a [Reason:] The function returns 1 if search was successful else returns 0.

4. What will be the output of the following PHP code?

  1.     <?php
  2.     $name = "What is your name?"
  3.     if (preg_match("/name/"),$name)
  4.     echo "My name is Will Pitt ";
  5.     else
  6.     echo "My name is not Will Pitt ";
  7.     if (preg_match("/are/"))
  8.     echo "I am great"
  9.     else
  10.     echo "I am not great";    
  11.     ?>

a) My name is Will Pitt I am great
b) My name is not Will Pitt I am great
c) My name is Will Pitt I am not great
d) My name is not Will Pitt I am not great

Answer

Answer: c [Reason:] The code uses preg_match to check for a keyword and replies based on whether it is true (1) or false (0).

5. Which one of the following preg PHP function is used to do a find and replace on a string or an array?
a) preg_replace()
b) preg_find()
c) preg_find_replace()
d) preg_findre()

Answer

Answer: a [Reason:] None.

6. What will be the output of the following PHP code?

  1.     <?php
  2.     $str = "Hello! My name is Cameron Fox. Coffee?"
  3.     $find = array('/is/','/coffee/');
  4.     $replace = array('/was/','/tea/');
  5.     echo preg_replace ($find, $replace, $str);
  6.     ?>

a) Hello! My name was Cameron Fox. tea?
b) Hello! My name is Cameron Fox. tea?
c) Hello! My name is Cameron Fox. Coffee?
d) Hello! My name was Cameron Fox. Coffee?

Answer

Answer: d [Reason:] Coffee was not replaced because the preg_replace function is case sensitive. Therefore it treats coffee and Coffee differently.

7. Which one of the following preg PHP functions is used to take a string, and put it in an array?
a) preg_destroy()
b) preg_split()
c) preg_unchain()
d) preg_divide()

Answer

Answer: b [Reason:] The string is broken up into different values in the array based upon your input.

8. What will be the output of the following PHP code?

  1.     <?php
  2.     $line = "You like dogs. I hate dogs. We should marry."
  3.     $sen = preg_split('/./', $line);
  4.     print_r($sen);
  5.     ?>

a) You like dogs. I hate dogs. We should marry.
b) Array([0]=>You like dogs. I hate dogs. We should marry.)
c) Array([0]=>You like dogs. [1]=>I hate dogs. [2]=>We should marry.)
d) Error

Answer

Answer: c [Reason:] We use a ‘.’ period to split the data, therefor giving each sentence it’s own array entry.

9. Which one of the following is not a preg PHP function?
a) preg_match
b) preg_match_all
c) preg_matchall
d) preg_split

Answer

Answer: c [Reason:] The function preg_matchall does not exist. preg_match_all is a preg function.

10. Parameter flags was added in which version of PHP?
a) PHP 4.0
b) PHP 4.1
c) PHP 4.2
d) PHP 4.3

Answer

Answer: d [Reason:] None.

PHP MCQ Set 4

1. Which one of the following class can not be instantiated?
a) inherited class
b) abstract class
c) constant class
d) every class

Answer

Answer: b [Reason:] An abstract class cannot be instantiated. Instead it defines (and, optionally, partially implements) the interface for any class that might extend it.

2. Which one of the following keywords is used to define an abstract class?
a) extends
b) implements
c) abstract
d) new

Answer

Answer: c [Reason:] The introduction of abstract classes was one of the major changes ushered in with PHP 5. Its inclusion in the list of new features was another sign of PHP’s extended commitment to object-oriented design.

3. Which one of the following is the correct abstract method?
a) public function write()
b) abstract function write()
c) abstract public write();
d) abstract public function write();

Answer

Answer: d [Reason:] An abstract method cannot have an implementation. You declare it in the normal way, but end the declaration with a semicolon rather than a method body.

4. Atleast how many abstract methods must an abstract class contain?
a) None
b) One
c) Two
d) Five

Answer

Answer: b [Reason:] Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract.

5. Which one of the following keyword is used to implement an interface?
a) interface
b) get
c) inherit
d) implements

Answer

Answer: d [Reason:] A class can implement an interface using the implements keyword in its declaration.

6. Which version of PHP introduced the concept called late static binding?
a) PHP 4
b) PHP 5
c) PHP 5.1
d) PHP 5.3

Answer

Answer: d [Reason:] None.

7. Which one of the following methods in the exception class, is used to get a nested exception object?
a) getPrevious()
b) getCode()
c) getFile()
d) getLine()

Answer

Answer: a [Reason:] getCode() – Get the code integer that was passed to the constructor. getFile() – Get the file in which the exception was generated. getLine() – Get the line number at which the exception was generated.

8. Which one of the following keyword is used in conjunction with an Exception object?
a) throws
b) exception
c) throw
d) final

Answer

Answer: c [Reason:] The throw keyword is used in conjunction with an Exception object. It halts execution of the current method and passes responsibility for handling the error back to the calling code.

9. Which keyword is used to put a stop on inheritance?
a) stop
b) end
c) break
d) final

Answer

Answer: d [Reason:] A final class cannot be subclassed.

10. PHP provides built-in interceptor methods, which can intercept messages sent to undefined methods and properties. This is also known as _________
a) overloading
b) overriding
c) overbending
d) overbinding

Answer

Answer: a [Reason:] None.

PHP MCQ Set 5

1. What is the full form of DNS?
a) Digital Network System
b) Domain Network System
c) Digital Name Systmem
d) Domain Name System

Answer

Answer: d [Reason:] The Domain Name System(DNS) is what allows you to use domain names(e.g., example.com) in place of the corresponding IP address, such as 192.0.10.10.

2. Which one of the following function checks for the existence of DNS records?
a) checkdns()
b) checkdnsr()
c) checkdnsrr()
d) checkdnsa()

Answer

Answer: c [Reason:] DNS records are checked based on the supplied host value and optional DNS resource record type, returning TRUE if any records are located and FALSE otherwise.

3. Which one of the following function is used to return an array consisting of various DNS resource records pertinent to a specific domain?
a) dns_get_record()
b) dns_record()
c) dnsrr_get_record()
d) dnsrr_record()

Answer

Answer: a [Reason:] None.

4. Which one of the following function is used to retrieve the MX records for the domain specified by hostname?
a) getmx()
b) retrieve_mx()
c) getmxrr()
d) retrieve_mxrr()

Answer

Answer: c [Reason:] None.

5. What is the default port number of HTTP’s?
a) 70
b) 80
c) 90
d) 100

Answer

Answer: b [Reason:] None.

6. Which one of the following function returns the port number of a specified service?
a) getportname()
b) getservername()
c) getserverbyname()
d) getservbyname()

Answer

Answer: d [Reason:] Example- getservbyname(“http”,”tcp”) will return 80.

7. Which one of the following statements can be used to establish port 80 connection with www.nachi.com?
a) fsockopen(“www.nachi.com”, 80);
b) sockopen(80,”www.nachi.com”);
c) fsockopen(80,”www.nachi.com”);
d) sockopen(“www.nachi.com”, 80);

Answer

Answer: a [Reason:] The fsockopen() function establishes a connection to the resource designated by target on port.

8. Which one of the following function is used to send a e-mail using PHP script?
a) mail_send()
b) send_mail()
c) mailrr()
d) mail()

Answer

Answer: d [Reason:] mail(string to, string subject, string message,) using this you can send any mail.

9. How many configuration directives pertinent to PHP’s mail function are available?
a) 4
b) 5
c) 6
d) 7

Answer

Answer: b [Reason:] They are- SMTP, sendmail_from, sendmail_path, smtp_port, mail.force_extra_parameters.

10. Which of the following statements is used to add an attachment to the mail?
a) $mimemail->attachment(‘attachment.pdf’);
b) $mimemail=>attachment(‘attachment.pdf’);
c) $mimemail->addAttachment(‘attachment.pdf’);
d) $mimemail=>addAttachment(‘attachment.pdf’);

Answer

Answer: c [Reason:] Call the Mail_Mime object’s addAttachment() method passing in the attachment name and extension.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.