PHP Face question Summary three (basic article with answer)

Source: Internet
Author: User
Tags integer numbers set time setcookie tmp folder

Problem

1. How do I access session variables (sessions)?

A by $_get

B by $_post

C by $_request

D Through global variables

E. None of these are right.

2. Which function will let the server output the following header?

Set-cookie:foo=bar;

Answer: _______________

3. In the normal case of ignoring browser bugs, how to use a different domain name than the one previously set

Domain to access a cookie?

A Access via Http_remote_cookie

B No way

C Set a different domain name when calling Setcookie ()

D Send additional requests to the browser

E. Use Javascript to include a cookie in a URL to send

4. How does the index.php script access the value of the table cell e-mail? (Double choice)

A $_get[' email ']

B $_post[' email ']

C $_session[' text ']

D $_request[' email ']

E. $_post[' text ']

5. How will the following script affect the $s string? (Double choice)

25

$s = '

Hello

‘;

$ss = Htmlentities ($s);

Echo $s;

?>

A Angle brackets <> will be converted to HTML tags, so the string will grow longer

B No change

C When the string is printed on the browser, the angle brackets are visible

D When you print the string on a browser, the angle brackets and their contents are recognized as HTML tags, so you cannot

See

E. The string is destroyed because Htmlentities () is called

6. What happens if I don't set an expiration time for a cookie?

A Expire immediately

B Never expire

C Cookies cannot be set

D Expires at the end of a browser session

E. Expires only if the script does not produce a server-side session

7. Consider the following code: If the user enters "PHP" and "great" in two text fields, what does the script output?

echo $_get[' element ';

?>

A There's nothing.

B Array

C A hint

D Phpgreat

E. greatphp

8. Under HTTPS, how does the URL and query string be uploaded from the browser to the WEB server?

A These two are plaintext transmissions, after which the information is encrypted for transmission

B Encrypted transfer

C URL plaintext transmission, query string encrypted transmission

D URL encrypted transmission, query string plaintext transmission

E. To ensure encryption, the query string is converted to a header, which is transmitted in the POST message

9. What happens when a form that has two elements of the same name is submitted to a PHP script?

A They form an array, stored in the Super global variable array

B The value of the second element, plus the value of the first element, is stored in the Super global variable array

C The second element overrides the first element of the

D The second element is automatically renamed

E. PHP output a warning

10. How do I store an array in a cookie?

A Add a pair of parentheses to the cookie name []

B Using the Implode function

C Impossible, because there is a capacity limit

D Using the Serialize function

E. Add an ARRAY keyword to the cookie name

11. What does the following script output?

Ob_start ();

for ($i = 0; $i < $i + +) {

echo $i;

}

$output = Ob_get_contents ();

Ob_end_clean ();

Echo $ouput;

?>

A 12345678910

B 1234567890

C 0123456789

D There's nothing.

E. A hint

12. By default, PHP stores session data in ___.

A File system

B Database

C Virtual content

D Shared memory

E. None of the above

13. You will always fail when you write a cookie with a validity period to a particular computer, which on other computers

Normal. After checking the time that the client operating system returns, you find that the time and Web services on this computer

The time on the device is basically the same. And this computer is not a problem when visiting most other websites. May I ask this

What is the cause? (Double choice)

A The browser program is out of the problem.

B The client's time zone is not set correctly

C User's anti-virus software blocks all safe cookies

D Browser is set to block any cookies

E. Illegal characters are used in cookies.

14. Assuming the browser does not restart, the session will expire after the last visit and be

Recovery?

A After 1440 seconds

B After the Session.gc_maxlifetime set time is over

C Never expire unless you delete it manually

D Never expire unless the browser restarts

E. None of these are right.

15. Which function converts the newline to an HTML tag?

Answer: ____________

Answer

1. Although Register_globals is set to ON, the session can be accessed through global variables, but in newer

In this PHP, in order to avoid the security implications, the php.ini file has set Register_globals to off

The So the answer is E.

2. Although the header function can be used here, the problem is clearly said to be Setcookie or Setrawcookie functions.

3. The answer is B. The browser does not allow HTTP transactions from a domain name to change the cookie under another domain name, no

This will result in serious security problems.

4. Now that the form is transferred by post, the script will only be possible from $_post and $_request two super-full

The value is taken from the local variable array. The element name (email) is the key name, so the answer is B and D. Note that due to the

Can lead to potential security problems, the use of $_request is discouraged here.

5. Test your understanding of HTML coding and the ability to debug code. The variable $s is htmlentities () at the function

The result is returned to the variable $ss, and $s itself has not been changed. So the answer is B and D. You may

Feel like you've been teased, but remember, finding such a small mistake is an important part of the ability to catch worms.

6. If no expiration time is set, the cookie will expire automatically at the end of the user session. Cookies do not require a server

End-of-session support, so the answer is D.

7. Forms are transmitted using post, so whatever you enter in the text box, the value is passed to the $_post super

Global variables, where the $_get array has no value. The answer is a.

8. When HTTPS transmission occurs, the browser and the server immediately complete the encryption mechanism of the handshake, and then the data are encrypted

Transmission instead of clear text-including URLs, query strings. And in the HTTP transmission, they are all

, so the answer is B.

9. For the received query string and POST information, PHP simply adds elements to the corresponding number of super variables

Group. The result is that if there are two elements with the same name, the previous one will be overwritten by the latter one. The answer is C.

10. Only B is always right. Although you can use the Implode function to convert an array into a string and then exist in the array,

However, there is no guarantee that you will be able to use serialize () to restore this string to an array in the future. Browser to a single cookie

There is a capacity limit, so storing an array in a cookie is not a good idea. But things are not always like this, you

You can still store some smaller arrays.

11. This is another test of the ability to debug the problem. Did you notice that at the end of the script, the $output in the Echo statement

The variables are spelled wrong! The script will not output anything, the answer is E.

12. The answer is file System (A). By default, PHP stores all session information in the/tmp folder;

With this folder in the operating system (e.g. Windows), you must set the Session.save_path in the php.ini

Position (e.g. c:\Temp) in a suitable location.

13. B and D are places where problems are most likely and should be investigated in depth. Because browser access to other sites is normal,

So it can't be that the browser program is out of the question. Antivirus software typically does not selectively block only secure cookies

(However, it is possible to block all cookies). You should first check if the browser is set to block all

Cookie, which is the most likely cause of the problem. Also, the wrong time zone setting may be the root cause-

The cookie is set to expire at GMT time. Cookies may appear to expire immediately when they are written, from

and cannot be received by the script.

14. Session.gc_maxlifetime sets the time interval between the last request of the user and the session being reclaimed.

Although the data file is not actually deleted, you will not be able to do this session once the session is recycled

Access. Coincidentally, the default setting for Session.gc_maxlifetime is exactly 1440 seconds, but this number is

To be adjusted by the system administrator. So the answer should be B.

15. Function NL2BR can implement this function.

Array

The most powerful feature of PHP is probably working with arrays. PHP allows developers to create a variety of different data types

An array of keys and values, and allows you to sort, split, and combine them with a variety of operations.

The greater the power, the greater the responsibility. Finding the best way to deal with such complex arrays is not an easy thing to do.

This chapter examines your understanding of the working mechanism of an array-not only in theory, but also in practice. On the other hand test

Observe your "manual processing" simple script--the ability to point out what went wrong or what the script would output.

Problem

1. The key of the indexed array is ___, and the key of the associative array is ___.

A Floating point, string

B Positive number, negative number

C Even, string

D String, Boolean value

E. Integral type, string

2. Consider the following array, how can I find the value cat from the array $multi_array?

$multi _array = Array ("Red",

"Green",

"Blue",

"Yellow" = = Array ("Apple", 9 = "pear", "banana",

"Orange" = = Array ("Dog", "Cat", "Iguana"));

?>

A $multi _array[' yellow ' [' apple '][0]

B $multi _array[' blue '][0][' orange '][1]

C $multi _array[3][3][2]

D $multi _array[' yellow ' [' orange '] [' cat ']

E. $multi _array[' yellow ' [' Orange '][1]

3. After running the following script, what is the contents of the array $array?

$array = Array (' 1 ', ' 1 ');

foreach ($array as $k = = $v) {

$v = 2;

}

?>

A Array (' 2′, ' 2′)

B Array (' 1′, ' 1′)

C Array (2, 2)

D Array (null, NULL)

E. Array (1, 1)

4. Which function should I use to sort the array in ascending order and preserve the index relationship?

A Ksort ()

B Asort ()

C Krsort ()

D Sort ()

E. Usort ()

5. Which function can convert an array to a string?

Answer: ____________

6. In what order will the following script output the elements within the array $array?

$array = Array (' A1 ', ' A3 ', ' A5 ', ' A10 ', ' A20 ');

Natsort ($array);

Var_dump ($array);

?>

A A1, A3, A5, A10, A20

B A1, A20, A3, A5, A10

C A10, A1, A20, A3, A5

D A1, A10, A5, A20, A3

E. A1, A10, A20, A3, A5

7. Which function can arrange the contents of the lower array in reverse order (i.e., array (' d ', ' C ', ' B ', ' a '))? (Double choice)

$array = Array (' A ', ' B ', ' C ', ' d ');

?>

A Array_flip ()

B Array_reverse ()

C Sort ()

D Rsort ()

E. None of these are right.

8. What does the following script output?

$array = Array (' 3 ' = ' a ', ' 1b ' = ' B ', ' C ', ' d ');

Echo ($array [1]);

?>

A 1

B B

C C

D A warning

E. A

9. Which method is most convenient for calculating the sum of all the elements in an array?

A Iterating through an array with a For loop

B Iterating through an array with a Foreach loop

C Using the Array_intersect function

D Using the Array_sum function

E. With Array_count_values ()

10. What does the following script output?

$array = Array (0.1 = ' a ', 0.2 = ' B ');

echo count ($array);

?>

A 1

B 2

C 0

D There's nothing.

E. 0.3

11. What does the following script output?

$array = Array (true = ' a ', 1 = ' B ');

Var_dump ($aray);

?>

A 1 = ' B '

B True = ' a ', 1 = ' B '

C 0 = ' a ', 1 = ' B '

D There's nothing.

E. Output NULL

12. The complexity of passing an array directly to a read-only function, regardless of its actual use, than by reference

Low?

A Yes, because when you pass it to a function, the interpreter needs to copy the array

B Yes, if the function modifies the contents of the array,

C Yes, if the array is large,

D Yes, because PHP needs to monitor the output of the function, has determined if the array has been changed

E. No

12. What does the following script output?

function Sort_my_array ($array)

{

return sort ($array);

}

$a 1 = Array (3, 2, 1);

Var_dump (Sort_my_array (& $a 1));

?>

A Null

B 0 = 1, 1 = 2, 2 = 3

C A reference error

D 2 = 1, 1 = 2, 0 = 3

E. BOOL (TRUE)

13. What does the following script output?

$result = ";

function glue ($val)

{

Global $result;

$result. = $val;

}

$array = Array (' A ', ' B ', ' C ', ' d ');

Array_walk ($array, ' glue ');

echo $result;

?>

Answer: ____________

15. What does the following script output?

$array = Array (1, 2, 3, 5, 8, 13, 21, 34, 55);

$sum = 0;

for ($i = 0; $i < 5; $i + +) {

$sum + = $array [$array [$i]];

}

Echo $sum;

?>

A 78

B 19

C Null

D 5

E. 0

Answer 1. The key name is an array of integer numbers (integers) called an indexed array, and the key name is an array of strings called associative arrays. The correct answer is E. 2. The cat is contained in two other arrays. In the first place, the key yellow must be used, followed by orange. The most internal array is an indexed array, and the string cat is the second value, and its index is 1. The correct answer is E. 3. The answer is B. The foreach operation is a copy of the $array and therefore has no effect on the original value. 4. Only the Asort function can be sorted by preserving the original index relationship. The answer is B. 5. The Serialize function converts complex data structures into strings and can be converted back to the original structure using the Unserialize function. There is also the implode function, which can make all the elements in an array a string. 6. The function Natsort () uses the "natural sort" method to sort the array. In the subject, the array elements have been "naturally" arranged so that the function does not alter the array at all. The answer is a. 7. Array_flip () can only swap the keys and values of each element in the array. Rsort () and Array_reverse () are able to reverse-order the array in question into the desired form (' d ', ' C ', ' B ', ' a '). The answer is B and D. 8. When you set a number key for an element in an array, PHP starts with the lowest available number and increments the setting. If you do not specify a number from which to start, PHP will start at 0. In the subject, 3 is the key of the first element, so the key of the third element is set to 4, and the last element is 5. Note that 1b is not a number. Therefore, the key is 1 and the value does not exist, and the answer is D. 9. The Array_sum function computes the sum of all the elements in the array. The answer is D. 10. Script Output 1 (answer is a). Because only integer numbers and strings can be used to make arrays of keys-floating-point numbers are converted to integer numbers. So 0.1 and 0.2 will be converted to 0, $array only 0=> ' B ' this element. 11. This question tries to divert your attention from the real problem. True equals the number 1, so the $array array will contain only one element. However, there was an error in the Var_dump () function--$array was misspelled into a $aray, and a "R" was missing. So var_dump will output NULL (or it might be a hint, depending on your settings). The answer is E. 12. The problem is a bit of a detour. First, note the two point: first, you are not necessarily going to use these two methods to pass an array. If you need to use a function to modify the contents of an array, passing by reference willIs the only way--but not in this case; second, the topic emphasizes passing an array to a read-only function. If this is not the case, the answer will be B, since the change to the array will result in a copy of it. However, under normal circumstances, PHP needs to create a structure to maintain a reference, on the other hand, because PHP uses lazy copy (lazy-copy)-also known as copy-on-write (Copy-on-write)-mechanism, the variable will not produce a copy before being changed, Therefore, passing an array by reference to a function that does not modify the contents of an array is slower than passing through a value, and passing by value is a quick and secure way to share an array among functions. The answer is E. 13. The answer is E. The sort function does not produce or return an array copy, but instead directly operates on the array ontology passed to it. The function returns only a Boolean value of true, which means that the sort succeeds (or false, which represents an error). Note that the array $a1 reference is passed to Sort_my_array (), which we do not agree to, and that the reference should be re-declared in the function. 14. The Array_walk function applies a specified function to each element in the array. So the script glue function will link all the elements in the array to the output ABCD. 15. The main test of your ability to analyze scripts. You may find this difficult to understand--but we have to deal with such unpleasant problems when we debug code written by others. This is pretty straightforward compared to some of the code we've seen. The For loop in the script is 5 times, and each time the key is the value of the value $i the key in the array $array is added to the $sum. This may sound like a tongue twister, but if you think about it one step at a time, you will find that when $i equals zero, $array [$array [$i]] equals to $array[$array [0], which is $array[1], which is 2. Along this line of thinking, the final answer is 78. string and regular expression string is PHP's "Swiss Army Knife"-as a Web development language, PHP most often deal with the string. So for developers, working with strings is a very basic skill. Fortunately, PHP's handling of strings is fairly easy to learn due to the efforts of the PHP development team. You just have to go through the first hurdle and then Yimapingchuan. However, this part of PHP is not a perfect feature. This chapter tests your understanding of strings and the function of handling strings. In addition, you have to face the art of writing a regular expression-a very useful tool that is always being tested by developers.

PHP Face question Summary three (basic article with answer)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.