MCQs On Class 1
Introduction to PHP
1. What does PHP stand for? a) Personal Home Page Answer: c) PHP: Hypertext Preprocessor 2. Which of the following is NOT a feature of
PHP? a) Server-side scripting Answer: c) Client-side scripting 3. Which of the following is a common use of
PHP in web development? a) Styling HTML content Answer: b) Managing databases 4. Which of the following tools is NOT
typically used to set up a PHP development environment? a) XAMPP Answer: d) Photoshop 5. What command is used to display PHP
configuration information and verify the PHP installation? a) echo "PHP"; Answer: c) phpinfo(); 6. In which tag do we write PHP code inside
an HTML file? a) <php> Answer: d) <?php ... ?> 7. What is the primary role of PHP in web
development? a) To add styles to HTML elements Answer: b) To process and generate dynamic content on the server 8. Which one of the following servers is used
by default when setting up XAMPP? a) Nginx Answer: c) Apache 9. What does the function phpinfo() output
when run in a PHP script? a) The HTML content of the webpage Answer: b) Information about the PHP configuration, such as version and
installed modules 10. After setting up a local development
environment with XAMPP/WAMP/MAMP, where should you place your PHP files to
run them via a browser? a) Anywhere on the desktop Answer: b) Inside the root directory of the web server (e.g., htdocs in
XAMPP) 11. Which of the following is true about PHP? a) PHP can only be used on Windows servers. Answer: c) PHP code is executed on the server-side. 12. What is the default file extension for
PHP files? a) .html Answer: b) .php 13. Which of the following statements about
PHP is false? a) PHP is platform-independent. Answer: c) PHP is a client-side scripting language. 14. In which of the following ways can PHP
scripts be executed? a) In a web browser via a web server Answer: d) All of the above 15. Which of the following is NOT a popular
web server that can run PHP? a) Apache Answer: d) PostgreSQL 16. Which of the following commands is used
to start the Apache server in XAMPP? a) Start MySQL Answer: c) Start Apache 17. Which PHP version introduced the Zend
Engine? a) PHP 4 Answer: a) PHP 4 18. How can you test if a web server is
properly running PHP? a) Create a .html file and open it in a
browser. Answer: c) Place a file with <?php echo "Hello, World!";
?> in the server's root directory and access it via a browser. 19. Which of the following is true when
embedding PHP code within an HTML file? a) PHP code is executed before the HTML is
sent to the browser. Answer: a) PHP code is executed before the HTML is sent to the browser. 20. What is the purpose of using
XAMPP/WAMP/MAMP in PHP development? a) To create complex animations Answer: b) To simulate a web server environment on a local machine 21. Which of the following is required to run
PHP scripts on your local machine? a) A text editor Answer: d) All of the above 22. What is the role of htdocs (or www in
WAMP/MAMP) in a local development environment? a) It is where the PHP interpreter is
located. Answer: c) It is the root directory where PHP files should be placed to
be accessible via the browser. 23. What is the main reason for using PHP in
web development? a) To style web pages with CSS Answer: d) To generate dynamic content and interact with databases 24. Which of the following commands is used
to stop the Apache server in XAMPP? a) Stop PHP Answer: c) Stop Apache 25. Which PHP function is commonly used to
check for syntax errors in PHP code? a) syntax_check() Answer: d) PHP does not have a built-in function for syntax checking,
but tools like php -l can be used 26. Which of the following best describes
PHP? a) PHP is a database management system. Answer: c) PHP is a server-side scripting language used for web
development. 27. What is the primary function of the PHP
interpreter? a) To compile PHP code into machine code. Answer: b) To execute PHP code on the server and generate HTML content. 28. Which of the following is the correct
syntax for embedding PHP code within an HTML file? a) <php> ... </php> Answer: c) <?php ... ?> 29. Which of the following is NOT a valid way
to start a PHP block? a) <?php Answer: d) <%php 30. When using XAMPP, which folder typically
serves as the root directory for your web files? a) /usr/local/bin/ Answer: b) C:\xampp\htdocs\ 31. How can you check the PHP version
installed on your local machine using the command line? a) php --version Answer: d) Both a) and b) 32. What happens when you try to run a PHP
script on a server that does not have PHP installed? a) The PHP code is executed but with errors. Answer: b) The PHP code is displayed as plain text in the browser. 33. Which of the following is the correct way
to declare a PHP variable? a) $variable_name = value; Answer: a) $variable_name = value; 34. In a local development environment, which
of the following URLs might you use to access a PHP file named test.php
located in the root directory (htdocs) of XAMPP? a) http://localhost/test.php Answer: a) http://localhost/test.php 35. What does the <?php ... ?> tag do
in an HTML file? a) It indicates the start and end of a PHP
script. Answer: a) It indicates the start and end of a PHP script. 36. Which of the following functions is
commonly used in PHP to output text or HTML to the browser? a) display() Answer: d) echo() 37. What is the purpose of using a local
development environment like XAMPP/WAMP/MAMP? a) To host a website on the internet. Answer: b) To test and develop web applications locally without needing
an internet connection. 38. Which of the following best describes the
phpinfo() function in PHP? a) It displays information about PHP syntax
errors. Answer: b) It outputs information about the PHP configuration and
environment. 39. If a PHP script is not working as
expected, what is the best way to start troubleshooting? a) Delete the script and start over. Answer: c) Check the error log or use debugging techniques to identify
the issue. 40. Which of the following statements is true
about PHP variables? a) PHP variables are case-insensitive. Answer: c) PHP variables are prefixed with a dollar sign $. 41. Which of the following methods can be
used to access PHP files in a browser when using XAMPP? a) Typing the PHP code directly into the
browser's address bar. Answer: b) Saving the PHP file in the htdocs directory and accessing it
via http://localhost/filename.php. 42. What is the primary purpose of a
server-side scripting language like PHP? a) To style web pages using CSS. Answer: c) To handle requests and generate dynamic web content on the
server before sending it to the client. 43. What will happen if you place a PHP file
in the htdocs folder of XAMPP but the Apache server is not running? a) The PHP file will execute normally. Answer: c) The browser will display a "Server Not Found"
error. 44. Which of the following is required to
view the output of a PHP script in a web browser? a) A PHP interpreter installed on the client
machine. Answer: b) A running web server like Apache or Nginx. 45. Which of the following components is
typically NOT included in XAMPP? a) Apache Answer: d) Python 46. If you receive a "500 Internal
Server Error" when running a PHP script on your local server, what is
the most likely cause? a) The PHP script contains a syntax error. Answer: a) The PHP script contains a syntax error. 47. Which of the following PHP tags is used
to output content directly to the browser without using echo? a) <?php ... ?> Answer: b) <?= ... ?> 48. In the XAMPP control panel, which action
should you take to start the MySQL database server? a) Click on the "MySQL Admin"
button. Answer: b) Click on the "Start" button next to MySQL. 49. What is the significance of using
phpinfo(); in a PHP script? a) It checks for syntax errors in the PHP
script. Answer: b) It outputs the current PHP version and configuration
settings. 50. Which of the following statements is true
about the localhost in a PHP development environment? a) localhost refers to an external server on
the internet. Answer: b) localhost is the default hostname that points to your own
computer. 51. What will happen if you try to run a PHP
script without starting the Apache server in XAMPP? a) The script will execute with limited
functionality. Answer: b) The script will open as a text file in the browser. 52. Which of the following options is used to
stop both Apache and MySQL services in XAMPP? a) Close the XAMPP control panel. Answer: b) Click "Stop" next to Apache and MySQL in the XAMPP
control panel. 53. What file extension should be used when
saving a PHP script to ensure it executes correctly on the server? a) .html Answer: b) .php 54. When working with PHP, what is the
purpose of the echo statement? a) To define a new PHP function. Answer: c) To output text or HTML content to the browser. 55. Which of the following is true about
PHP's compatibility? a) PHP only works with Apache servers. Answer: b) PHP is compatible with multiple operating systems, including
Windows, macOS, and Linux. 56. Which of the following will correctly
display "Hello, World!" in a browser when running a PHP script? a) <?php echo "Hello, World!";
?> Answer: a) <?php echo "Hello, World!"; ?> 57. Why is PHP considered a
"server-side" scripting language? a) Because it can be embedded in HTML files. Answer: b) Because it is executed on the server before the result is
sent to the client's browser. 58. Which of the following commands is used
to access the XAMPP control panel in Windows? a) Open the terminal and type xampp start. Answer: b) Double-click the xampp-control.exe file in the XAMPP
installation directory. 59. What is the purpose of a
"localhost" environment in PHP development? a) To simulate a live server environment on
your local machine. Answer: a) To simulate a live server environment on your local machine. 60. Which of the following actions should you
take if the Apache server in XAMPP is not starting? a) Restart your computer. Answer: b) Check for port conflicts (e.g., port 80) and change the port
settings in XAMPP. |