You need to store a price, which includes cents, in a variable in your PHP script. What type of number would you use and why?

  • float
  • integer
  • string
  • boolean
In this case, you would use the float data type to store a price that includes cents in a variable in your PHP script. The float data type allows for the representation of real numbers with a decimal point, which is suitable for storing prices that may have fractional values, such as cents. Integer data type is not suitable as it does not allow for decimal points. String data type could be used, but it is more appropriate to use float to perform arithmetic calculations if needed. Learn more: https://www.php.net/manual/en/language.types.float.php

To sanitize a string in PHP, you can use the filter_var() function with the FILTER_SANITIZE_STRING ______.

  • filter
  • sanitize
  • validate
  • clean
To sanitize a string in PHP, you can use the filter_var() function with the FILTER_SANITIZE_STRING flag. This flag specifically sanitizes the string by removing HTML tags and encoding special characters to make the string safe for output. The filter_var() function provides an easy and efficient way to sanitize strings in PHP. For more details, see: http://php.net/manual/en/function.filter-var.php

OOP in PHP stands for Object-Oriented ______.

  • Programming
  • Protocol
  • Parsing
  • Processing
In the context of PHP, OOP stands for Object-Oriented Programming. It is a programming paradigm that focuses on creating objects and defining their behavior using classes, inheritance, encapsulation, and polymorphism. The correct option is "Programming." For further details, refer to the PHP documentation on object-oriented programming: http://php.net/manual/en/language.oop5.php

You have installed PHP on your local machine, but your PHP script isn't running. What could be potential reasons for this?

  • PHP isn't properly installed.
  • The web server isn't properly configured to handle PHP files.
  • The PHP file has a syntax error.
  • All of the above.
There could be several reasons why a PHP script isn't running. PHP might not be properly installed, or the web server might not be correctly configured to handle PHP files. There could also be syntax errors within the PHP script that prevent it from executing correctly. In some cases, file permissions or the PHP configuration file (php.ini) settings can also cause issues. Learn more: https://www.php.net/manual/en/install.php

What are some FTP-related functions available in PHP?

  • ftp_connect(), ftp_login(), ftp_put()
  • array_merge(), json_encode(), htmlspecialchars()
  • trim(), substr(), strtolower()
  • All of the above
PHP provides several FTP-related functions for working with FTP servers. Some commonly used FTP functions in PHP include ftp_connect() (to establish an FTP connection), ftp_login() (to log in to an FTP server), and ftp_put() (to upload a file to an FTP server). Other functions like ftp_get() (to download a file), ftp_nlist() (to retrieve a directory listing), ftp_mkdir() (to create a directory), and ftp_delete() (to delete a file) are also available. These functions allow PHP scripts to interact with FTP servers and perform file transfer operations.

Which PHP loop will execute a block of code at least once, then it will repeat the loop as long as the condition is true?

  • while loop
  • for loop
  • do-while loop
  • foreach loop
The do-while loop in PHP will execute a block of code at least once, and then it will repeat the loop as long as the specified condition is true. In this loop, the condition is checked after the code block is executed, ensuring that the block of code is executed at least once. If the condition evaluates to true, the loop will continue to repeat. If the condition evaluates to false, the loop will terminate. The do-while loop is useful when you want to guarantee the execution of the code block at least once, regardless of the condition. Learn more: https://www.php.net/manual/en/control-structures.do.while.php

You need to replace a certain word in a string in your PHP script. How would you do this?

  • str_replace($search, $replacement, $string)
  • replace($search, $replacement, $string)
  • substr_replace($search, $replacement, $string)
  • swap($search, $replacement, $string)
To replace a certain word in a string in PHP, you can use the str_replace() function. The str_replace() function performs a search and replace operation on a given string. It replaces all occurrences of the specified search string with the replacement string. Pass the search string, replacement string, and the original string as arguments to the str_replace() function, like this: str_replace($search, $replacement, $string). This will return a new string with the replaced word. Learn more: https://www.php.net/manual/en/function.str-replace.php

In PHP, a function is a self-contained block of code that performs a specific task.

  • TRUE
  • FALSE
Yes, in PHP, a function is a self-contained block of code that performs a specific task. It is a way to organize and reuse code in a modular manner. Functions can take input parameters and return a value or perform an action. They help improve code readability and maintainability. Learn more: https://www.php.net/manual/en/functions.user-defined.php

A common use case for the $_SERVER superglobal in PHP is to access the ______.

  • Client's IP address and user agent
  • Server's file system and directory structure
  • Database connection details and credentials
  • User input from form submissions
A common use case for the $_SERVER superglobal in PHP is to access the client's IP address and user agent. By using $_SERVER['REMOTE_ADDR'], you can obtain the client's IP address, and $_SERVER['HTTP_USER_AGENT'] provides information about the client's user agent, such as the browser and operating system. This information can be useful for various purposes, including security, logging, personalization, and analytics. Learn more: https://www.php.net/manual/en/reserved.variables.server.php

PHP is a client-side scripting language.

  • TRUE
  • FALSE
PHP is primarily a server-side scripting language. The PHP code is processed on the server, and the result is sent as HTML to the client's browser. Learn more: https://www.php.net/manual/en/intro-whatcando.php