PHP

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

list some logical operators

! negation AND and && and OR or || or XOR or not

besides GET and POST, what other predefined variable can you use to access data?

$_REQUEST, but $_POST and $_GET are more precise, and therefore preferable.

what type of variable is $_SERVER

$_SERVER is a predefined variable.

what shorthand can you use to increment? decrement?

$var++ and $var-- respectively.

what operator can you use to find the remainder of $x divided by $y?

$z = $x % $y; $z will yield the remainder of $x / $y

what are some basic arithmetic operators?

+ addition - subtraction * multiplication / division

what operators can you use to operate and assign?

+=, -=, *=, /= $num += 5 will yield $num + 5 $num /= 5 will yield $num / 5

what is the concatenation assignment operator?

.= $greeting = 'hello, '; $greeting =. 'world!'; $greeting yields 'hello, world!'

what tag begins a php script?

<?php

list some comparison operators

== equality != inequality < less than > greater than <= less than or equal to >= greater than or equal to

what tag ends a php script?

?>

what are the seven main error reporting constants?

E_NOTICE, E_WARNING, E_PARSE, E_ERROR, E_ALL, E_STRICT, E_DEPRECATED

describe the error type 'Error'

Error is fatal, it is a general fatal error: memory allocation problem.

describe the error type 'Notice'

Notice is not fatal, but may or may not be indicative of a problem: referring to a variable with no value.

what are the four main error types?

Notice, Warning, Parse error, and Error.

describe the error type 'Parse error'

Parse error is fatal, caused by a semantic mistake: omission of a semicolon, imbalance of quotations, parentheses, or braces.

describe the error type 'Warning'

Warning is not fatal, but is probably problematic: misusing a function.

what is a control structure?

a conditional or loop.

what will happen if $_POST['name'] is used in double quotes?

a parse error will occur, to avoid this, create shorthand variables like: $name1 = $_POST['name1']; $name2 = $_POST['name2'];

what function can be used to find the absolute value of a number or numeric variable?

abs()

how many arguments can isset() take?

any amount.

what function can be used to round up to the highest integer?

ceil()

what can htmlentities() be used for?

converts all HTML tags into their entity versions. <span> -> &lt;span&gt;

what function can be used to round down to the lowest integer?

floor()

how does round() handle 0.5, 0.05, etc. rounds?

half the time it rounds up, half the time it rounds down.

what counters htmlentities()?

html_entity_decode()

what two conditionals does PHP have?

if and switch.

what can you use to display errors in a particular script?

ini_set ('display_errors', 1); should be placed at top of script.

what is the function getrandmax() for?

it contains the highest value that rand() can have randomly

what can htmlspecialchars() be used for?

it converts certain HTML tags into their entity versions. <span> -> &lt;span&gt;

what will error_reporting (0) do?

it will not show error reporting, it will be turned off.

what will error_reporting (E_ALL & -E_NOTICE) do?

it will show all error reporting except for notice errors.

what will error_reporting (E_ALL) do?

it will show all error reporting.

what will error_reporting (E_ALL | E_STRICT) do?

it will show all errors that fall under E_ALL or E_STRICT, the pipe | is used for 'or' so that errors that fall under either will be shown; E_ALL & E_STRICT would be incorrect for this purpose because the error would have to fall under both E_ALL and E_STRICT.

what will strip_tags(nl2br($string)) do?

nl2br will replace any new lines in $string with <br /> tags, and then strip_tags will remove any HTML or PHP tags, including the just inserted <br /> tags; use nl2br(strip_tags($string)) instead.

what is the default number of decimals that round() will round to?

no decimals, it will round to the nearest integer.

will print $_GET work? why or why not?

no, because you cannot use the print function on arrays.

will print $_POST work? why or why not?

no, because you cannot use the print function on arrays.

will print $_SERVER work? why or why not?

no, because you cannot use the print function on arrays.

can variable names begin with numbers?

no.

can variable names contain symbols?

no.

is data shown in the URL if POST is used?

no; use for passwords, pages that would not be bookmarked, pages that require security.

what can be used to print data in an array?

not print; print_r (human readable) can be used.

what function can you use to format a number with commas?

number_format()

what types of arguments are used for error_reporting()?

predefined constants that are not in quotations.

where is data sent using GET found?

predefined variable $_GET

where is data sent using POST found?

predefined variable $_POST

what type of variable is $_GET?

predefined variable.

what type of variable is $_POST?

predefined variable.

what function can you use to create a random number?

rand() function.

what can strip_tags() be used for?

removes all HTML and PHP tags.

why should you use comments before you shorthand variables for POST and GET?

so you know which values are being passed from the form. // feedback.html passes title, name, email, response, comments $title = $_POST['title'] ...

what can you use to case-sensitively replace substrings with other strings?

str_replace()

what should the action attribute's value contain?

the URL to the php script that will handle the information in the form.

what character must all variables begin with?

the dollar sign $.

what should be used to have multiple quotations in one string?

the escape character '\': $string = "I said \"Hello\" to the man.";

what can the number_format() function be used for? (two answers)

the function will format with commas and the second argument can determine how many decimals to round to.

what number do indices end at?

the length minus one, and they always begin at zero.

what are the first and second optional arguments of rand()?

the lower limit and the upper limit for $num = rand(0, 10) $num must be between 0 and 10.

what is the second optional argument of the number_format() function?

the number of decimal places to round to. number_format(125939.4958670, 3) will yield 125,939.496

what is the optional second argument of the round() function?

the number of decimal places to round to. round(12.4958670, 3) will yield 12.496

what is the first argument of the number_format() function?

the number or numeric variable to be formatted.

what is the first argument of the round() function?

the number or numeric variable to be rounded.

define precedence

the order of operations.

what is the concatenation operator?

the period; .

what happens if you omit the third argument of substr()?

the substring will contain the rest of the string starting at the index value provided by the second argument.

how do you know what to use to get a value from POST or GET?

they are the values of the name attributes of the input tags in the form. $_POST['name'] or $_GET['name'] refers to the value of <input name="name" /> (depending on the method of the form).

define concatenate

to append; add a string to the end of another string.

what can empty() be used for?

to check if a given variable has an "empty" value - no value, 0, or FALSE.

what can is_numeric() be used for?

to check if a variable has a valid numerical value; strings with numerical values pass.

what can isset() be used for?

to check if a variable has any value (including 0, FALSE, or an empty string). $var1 = 0; $var 2 = 'something'; isset(var1); // TRUE isset(var2); // TRUE isset(var); // FALSE

what is the nl2br() function used for?

to convert new lines in a variable from a form to <br /> tags so that the data can be formatted correctly.

what can strtok() be used for?

to create a substring (referred to as a token) from a larger string; $first = strtok($_POST['name'], ' ') finds first name because first and last name is separated by a space.

what can crypt() be used for?

to encrypt values; it is a one-way encryption method, but you can compare $data to crypt($string), if, say, $string is a password as user has entered and $data is the password on file.

what can substr() be used for?

to find a substring in a larger string using indices; $sub = substr($string, 2, 10) assigns $sub ten characters of $string starting at the second character of $string.

what can str_word_count() be used for?

to find the amount of words in a string.

what can strlen() be used for?

to find the length of a string; strlen('Hello, world!') would yield 13

what can trim() be used for?

to remove any white space - spaces, newlines, tabs - from the beginning and end of a string, not the middle.

what can str_ireplace() be used for?

to replace a substring with another string; $me = 'first i. last'; $me = str_ireplace('i.', 'initial', $me); print $me; // 'first initial last' it is not case-sensitive.

what is the round() function used for?

to round numeric values.

what is an 'index' or 'key'?

what is referred to for a value within an array. $_POST['name'] may be equal to 'Jane Doe' $cards[4] may be equal to 'BMW'

when should you use double quotes?

when a variable contains any amount of variables; in general.

what can urlencode() be used for?

when applied, the value can be passed safely through the URL (GET).

what can urldecode() be used for?

when applied, the value is decoded from its encoded nature; firstname+last name -> firstname lastname.

when should you use single quotes?

when there are no variables in the string; if you use single quotes, PHP will not search for variables to replace, which can enhance speed.

how can you set up error reporting?

with the function error_reporting();

what can wordwrap() do?

word wrap after a certain amount of characters.

is round($num) the same as round ($num)

yes, spaces are optional and not required after a function.

can arrays contain arrays?

yes, they commonly do contain arrays.

are variable names case-sensitive?

yes.

can negative numbers be used with substr() to count backward?

yes.

can parentheses be used in conditional statements to set precedence?

yes.

can variable names begin with underscores?

yes.

can a string with numbers be used as a number?

yes. $string = "2"; can be used as $string = 2; can be used.

is data shown in the URL if GET is used?

yes; use for search engines, catalogued pages, pages that would be bookmarked.

how can you put a dollar sign before a variable like $10 where 10 is the variable's value?

you can escape the first dollar sign; \$$cost; or you can use curly braces; ${$total}

what if you want to use trim() for the beginning of a string?

you can use ltrim() (as in left-trim), because the left is the beginning of the string.

what if you want to use trim() for the end of a string?

you can use rtrim() (as in right-trim), because the right is the end of the string.

what number do indices begin at?

zero, and they continue to the length of the string minus one.

what will happen if there are no numbers to round? round (12, 2)

zeros will be added to the end.


Ensembles d'études connexes

PEDS Chapter 43: Nursing Care of the Child With an Alteration in Urinary Elimination/Genitourinary Disorder -

View Set

Chapter 34: Child Health Assessment

View Set

C7 Anti-Avoidance: Sec 84.1, Sec 55(2), GAAR

View Set

Chem 1110 Exam 1 Chapters 1 and 2

View Set

Chapter 3 Measures Of Central Tendency

View Set

Mexico Textbook Reading (Part 1)

View Set

BLS Section 3 Check your Knowledge

View Set

Data and Info. Management Chapter 8 (Marist College Eitel Lauria)

View Set