PHP Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

character entity

An HTML ________________ lets you display some special characters on a web page.

drop-down

In a/an ________________ list, only one option can be selected.

$name = explode(', ', $name); $last_name = $name[0]; $first_name = $name[1];

Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this:

length

The ________________ of a string specifies the number of characters that it contains.

!

The ________________ operator has the highest order of precedence of the logical operators.

&&

The ________________ operator is a logical operator that returns a TRUE value when the expressions on both sides of the operator are TRUE.

conditional

The ________________ operator is the only ternary operator available from PHP.

>=

The ________________ operator returns a TRUE value if the expression on its left is greater than or equal to the expression on its right.

format

The date() function makes it easy to create a timestamp for the current date and ________________ it before returning the value.

DateInterval

The diff() method of a DateTime object requires another DateTime object as its argument and returns a/an ________________ object.

print

The echo and ________________ statements are similar, but the echo statement can accept multiple parameters.

identity

The equality operators convert data from one type to another before performing a comparison, but the ________________ operators do not convert data before performing a comparison.

delimiter

The explode() function returns an array of strings from a single string based on the ________________ character that you specify.

find all errors in the application

The goal of testing is to

insensitive

The strcasecmp() function is case-________________. As a result, "Anders" comes before "zylka".

runtime error

The type of error that does not violate syntax rules, but causes the PHP interpreter to display errors is called a

DateTime

The use of ________________ objects resolves the Y2K38 problem because the upper limits of dates and times are essentially removed.

Y2K38

Timestamps will encounter a(n) _______ problem if they are not converted to DateTime objects.

new

To create a DateTime object for the current date, you use the ________________ keyword and pass no arguments to the constructor.

$days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days);

To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:

isset()

To test whether a check box has been checked, you can use the ________________ function.

Two cosigners needed.

What does $message contain after the following code executes? $age = 19; $score = 750; if ( $age >= 21 && $score >= 700 ) { $message = 'Loan approved'; } else if ( $age >= 21 && $score >= 650 ) { $message = 'Cosigner needed.'; } else if ( $age >= 18 && $score >= 680 ) { $message = 'Two cosigners needed.'; } else { $message = 'Loan denied.'; }

L: 0, 1, 2, 3, 4, 5, 6, 7,

What does $message contain after the following code executes? $message = "L: "; for ($i = 0; $i < 10; $i++ ) { $message .= $i . ", "; if ($i == 7) break; }

The file is in "C:\My Documents"

What is stored in $message by the code that follows? $message = "The file is in \"C:\\My Documents\"";

runs to the next breakpoint

When you click on the Continue button while you're debugging with NetBeans, the application

double

When you code a variable name within a string literal, you have to code the literal within ________________ quotation marks.

years, months, weeks, days, hours, minutes, seconds

When you create a DateInterval object, you pass it one argument that specifies one or more of the following:

the Step Into button to execute the current statement and move to the next statement

When you test an application with NetBeans and a breakpoint is reached, you can click

valid

When you test an application, you start by using ________________ data.

display any HTML tags entered by the user instead of processing them

When you use the htmlspecialchars() and nl2br() functions to process a user's entry and then pass that entry to a web page, the browser will

puts both "09" and "9" before "10"

A "natural" comparison of two values

interval/span

A DateInterval object represents a/an ________________ of time rather than a point in time.

timestamp

A ______________ is an integer that represents a date and time as the number of seconds since midnight, January 1, 1970.

relative

When you use the strtotime() function, you can use an absolute template to create a timestamp for the date that you specify, or you can use a ________________ template to create a timestamp for the current date and adjust it based on the offsets that you specify.

the starting position of the substring

When you use the substr() function to extract a substring from a string, you need to at least pass an argument that gives

into

When you're using NetBeans, you can step through the execution of an application one statement at a time by clicking on the Step ________________ button.

select

Which HTML element is used to create a drop-down list?

option

Which HTML element is used to create items in a drop-down list?

isset()

Which PHP function can be used to determine if a checkbox is checked?

htmlspecialchars()

Which PHP function converts some special characters into character entities?

htmlentities()

Which PHP function returns a string with all special HTML converted to the HTML entity?

strlen()

Which PHP function returns the number of characters in a string?

method

Which attribute of a form element determines how the data is passed to a file?

?

Which character is used to separate the original URL from the parameters that are appended to it?

diff()

Which method of a DateTime object can be used to determine an amount of time between two dates or times?

&

Which method of the form appends values to the URL to pass data?

GET

Which method of the form appends values to the URL to pass data?

equality operators, relational operators, logical operators

Which of the following can be used in a conditional expression?

format codes

You can use the sprintf() function to precisely format strings and numbers by specifying the required ________________ in the first argument that you pass to it.

A hidden field

doesn't appear on the form but its data is sent to the server

syntax

A/an ________________ error violates the rules for how PHP statements must be written.

test area

A/an ________________ is similar to a text field, but it can display multiple lines of text.

for

A/an ________________ loop is typically used when the loop requires a counter variable.

do-while

A/an ________________ loop tests its conditional expression at the end of the loop.

break

A/an ________________ statement can be used to jump out of a loop.

setDate()

After you create a DateTime object, you can use its setTime() method to change the time or its ________________ method to change the date.

logic error

An error that lets the application run but produces the wrong results is known as a

selection

An if statement can be used to implement a ________________ structure.

test

As you ________________ an application, you try to make it fail.

$card_type = filter_input(INPUT_POST, 'delivery');

Assume that the POST method is used. Which of the following statements gets the value of the radio button that's on in the delivery group and stores it in a variable named $card_type? <input type="radio" name="delivery" value="USPS">USPS <input type="radio" name="delivery" value="FedEx">Federal Express <input type="radio" name="delivery" value="UPS">UPS

FedEx

Assume that the second radio button in the code below has been selected by the user. When you get the value of that radio button, what will the value be? <input type="radio" name="delivery" value="USPS">USPS <input type="radio" name="delivery" value="FedEx">Federal Express <input type="radio" name="delivery" value="UPS">UPS

With character entities for special characters

Assume that the statements that follow get the data from a text area named comments. After these statements are executed, how will the $comments_esc variable be displayed by an echo statement? $comments = filter_input(INPUT_POST, 'comments'); $comments_esc = htmlspecialchars($comments);

2038

Because most systems today store timestamps as 32-bit signed integers, the upper limit of a timestamp on these systems is January 19 in the year________________.

GET

If a form uses the ________________ method, the data for the fields is displayed in the URL.

INF

If a number in a PHP application is larger than the maximum value that PHP provides for, it is converted into the PHP constant named ________________.

December 25, 2017

If the date is December 25, 2017, what output would be produced by the code below? echo date('F d, Y');

Dec. 25, 2017

If the date is December 25, 2017, what output would be produced by the code below? echo date('M. d, Y');

12/25/2017 12:00 AM

If the date is December 25, 2017, what output would be produced by the code below? echo date('n/d/Y h:i A');

12/25/2017

If the date is December 25, 2017, what output would be produced by the code below? echo date('n/j/Y');

12/25/17

If the date is December 25, 2017, what output would be produced by the code below? echo date('n/j/y');

$number = mt_rand(10,5000); $number *= 100;

If you want to generate a random number that ranges from 1000 to 500,000 as a multiple of 100 (1000, 1100, 1200, etc.), and store it in a variable named $number, you can use the code that follows.

round()

If you want to round a number within an arithmetic expression, which function should you use?

echo

A simple way to trace the execution of an application is to insert ________________ statements at appropriate points within the code.

position

A substring within a string is identified by its length and its starting ________________ within the string.

controller

A switch statement in PHP is often useful in the ________________ of an application that uses the MVC pattern.

expression

A switch statement in PHP starts by evaluating a switch ________________.

seconds

A timestamp stores the number of ________________ since midnight on January 1, 1970 GMT.

escape

By using ________________ sequences, you can put special characters into a string literal that would otherwise be interpreted incorrectly by PHP.

htmlentities()

By using the ________________ function, you can send special characters to the browser in a way that they will be displayed correctly.

0 years, 1 months, and 7 days overdue.

Code example 10-1 $current_date = new DateTime(); $due_days_diff = $current_date->diff($due_date); if ($current_date > $due_date) { $overdue_message = $due_days_diff->format( '%y years, %m months, and %d days overdue.'); } (Refer to code example 10-1) If $due_date contains a DateTime object for a date that comes 1 month and 7 days before the date stored in the $current_date variable, what will $overdue_message contain when this code finishes executing:

a DateInterval object

Code example 10-1 $current_date = new DateTime(); $due_days_diff = $current_date->diff($due_date); if ($current_date > $due_date) { $overdue_message = $due_days_diff->format( '%y years, %m months, and %d days overdue.'); } (Refer to code example 10-1) If $due_date contains a DateTime object, $due_date_diff will contain

<input>

HTML ________________ tags are used to define the text boxes, password boxes, radio buttons, and check boxes on a form.

3

How many operands does a ternary operator have?

2

How many radio buttons from the following code can be selected at any given time? <input type="radio" name="address" value="Home">Home Address <input type="radio" name="delivery" value="FedEx">Federal Express <input type="radio" name="delivery" value="UPS">UPS

name

In order to group multiple radio buttons so that only one of the radio buttons can be selected at a time, which attribute of the input element must have the same value for all radio buttons in the group?

max()

The ________________ function returns the largest value of the two or more arguments that are passed to it.

DateTime

One of the methods of a/an ________________ object lets you add a DateInterval object to it.

$i = strpos($name, ', '); $last_name = substr($name, 0, $i); $first_name = substr($name, $i+2);

Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this:

entities

The htmlspecialchars() function can be used to convert some of the special characters that a user has entered into a text box or text area into HTML character ________________. This provides a way to display special characters and helps to guard against XSS attacks.

stack trace

The list of functions in the reverse order in which they were called is called a/an

remove

The ltrim() and rtrim() functions let you ________________ all spaces from the front or back of a string.

<br>

The nl2br() function can be used to convert new line entries in a text area into HTML ________________ tags.

data

Type casting refers to PHP code that converts a value from one ________________ type to another.

POST

Typically, you would use the ________________ method if a form contains password fields or other sensitive data that you don't want to display in the URL.

interpolation

Variable substitution is carried out by what process that converts a variable's value to a string?

rate is valid

What does $message contain after the following code executes? $rate = 0.1; if ( ! is_numeric($rate) ) { $message = 'Rate is not a number.'; } else if ($rate < 0) { $message = 'Rate cannot be less than zero.'; } else if ($rate > 0.2) { $message = 'Rate cannot be greater than 20%.'; } else { $message = 'Rate is valid.'; }

Forbidden

What does $message contain after the following code executes? $statusCode = "403"; switch ( $statusCode ) { case "200": $message = "OK"; break; case "403": $message = "Forbidden"; break; case "404": $message = "Not Found"; break; default: $message = "Unknown Status"; break; }

empty string ('')

What does $salutation contain after the following code executes? $company_name = ''; $salutation = $company_name ?? 'To whom it may concern';

12.5

What does $shipping_cost contain after the following code executes? $quantity = 3; $shipping_cost = ($quantity > 1) ? 5 + ($quantity * 2.5) : 5;

single quotes, double quotes, heredoc

What is a way to assign a string to a variable in PHP?

/n, /t, /r

What is an escape sequence used in double-quoted strings in PHP?

fix all errors

What is the goal of debugging an application before it is put into production?

find all errors

What is the goal of testing an application before it is put into production?

misspelling keywords, forgetting to end a statement with a semicolon, forgetting a closing quotation mark

What would be considered a common syntax error in PHP?

variables

When a breakpoint is reached while you're testing an application with NetBeans, you can view the values of the available ________________.

breakpoint

When debugging an application, you can set a(n) ________________ to view the value of a variable at a particular point.

switch

When using the MVC pattern, the ________________ statement often works better than an if/else statement in the controller.

random_int()

Which of the following functions should you use to get a random number if security is a concern?

<, <=, >

Which of the following is a relational operator in PHP?

stack trace

Which of the following lists the functions in the reverse order in which they were called?

==, >=, !=

Which of the following operators perform type coercion?

$birthdate = mktime(0, 0, 0, 12, 2, 1969); $birthdate = strtotime('1969-12-02'); $birthdate = strtotime('12/02/1969');

Which of the following statements is a valid way to create a timestamp named $birthdate that represents December 2, 1969?

continue

Which of the following statements will restart the execution of a loop?

mulitiple

Which optional attribute of a select element allows the user to select more than one option in a list box?

runtime

Which type of error does not violate the rules for how PHP statements must be written but will cause the PHP interpreter to display errors?

syntax

Which type of error is considered the easiest to find?

syntax

Which type of error is considered the easiest to fix?

logic

Which type of error is often most difficult to find and fix?

radio

Which type of input element should be used on a form when the user can select only one of the options?

checkbox

Which type of input element should be used on a form when the user can select zero, one, or many of the options in a group?

do-while

Which type of loop will always execute its code at least once?

break

Which type of statement ends or jumps out of a loop?

continue

Which type of statement ends the current iteration of a loop?

iteration

While loops and for loops are often referred to as ________________ structures.


Kaugnay na mga set ng pag-aaral

Nutrition: Science and Applications Chapter 12 The Trace Minerals

View Set

[SECRET] Google Hangouts /Roll Guide

View Set

STUDY UNIT 8: Aids and experts used to investigate crime, irregularities and transgressions: digital forensics {362 to 393}

View Set