ÔÚ Unix Review ÉÏ¿´µ½Õa¸oºÜÓÐÒa˼µÄ²aÊÔ£¬ºÍ´o¼Ò¹²Ïi¡£
UnixReview.com
May 2007
Test Your Knowledge of PHP
by Emmett Dulaney
From: http://www.unixreview.com/documents/s=10130/ur0705d/
Increasingly, PHP seems to be the tool/language that is used to make Web sites dynamic. While it is far from the only open source scripting language available, PHP's abilities and features are quickly making it not only a must-have in the Web world but also a topic on many certification exams. Following are fifty questions on PHP at the knowledge level found on beginning/intermediate certification exams. Good luck (answers are at the end of the article)!
A. />
B. #>
C. ?>
D. .>
A. ==
B. ||
C. ===
D. ==?
A. Variable names in PHP are case sensitive.
B. Variable names in PHP are not case sensitive.
C. PHP variables need to be declared before they can be used.
D. PHP variables do not need to be declared before they can be used.
A. involve
B. need
C. include
D. call_for
A. // This is a comment
B. <?comment This is a comment />
C. # This is a comment
D. / This is a comment /
A. \n
B. \r
C. \t
D. \\
What file is used to configure global PHP settings? __ (Fill in the blank.)
If the value of $AU is currently 7, what is its value as a result of the command $AU++;
A. 8
B. 9
C. 14
D. 49
A. d
B. f
C. s
D. u
A. a & b
B. a && b
C. a | b
D. a || b
A. 100
B. 99
C. 1
D. 0
A. limit()
B. scope()
C. srand()
D. hinum()
A. A-Z
B. Z-A
C. 0-9
D. 9-0
A. They can contain an underscore character
B. They can begin with a numeric character
C. They can begin with an alpha character
D. They can contain alphanumeric characters
A. <?php
B. <php
C. </php
D. <P
A. brackets [ ]
B. parentheses ( )
C. curly braces { }
D. quotation marks ""
A. assign
B. assigntype
C. settype
D. type
A. ADDR_IP
B. ADDR
C. IP_ADDR
D. REMOTE_ADDR
A. POST
B. GET
C. SEND
D. READ
A. integer
B. double
C. string
D. Boolean
A. w
B. a
C. r+
D. w+
A. copy()
B. clone()
C. rename()
D. repr()
A. $cookie_expire = time() +24
B. $cookie_expire = time() +1440
C. $cookie_expire = time() +86400
A. =
B. #
C. |
D. ;
A. $days = ()
B. $days = array();
C. $days = ""
D. $days = initialize [ ]
E. 12345
F. 12,3,45
G. 1{2,3,4}5
A. file()
B. file_there()
C. exist_file()
D. file_exists()
A. $user
B. $COOKIE[user]
C. $_COOKIE[user]
D. $COOKIE_user
A. array_add()
B. array_merge()
C. array_join()
D. array_combine()
What function is used to determine whether a session has been started for the current user and then start one if necessary? __ (Fill in the blank.)
After opening a file with the fopen() function, what is used to close the file pointer?
A. fclose()
B. close()
C. die()
D. end()
A. echo show($remain);
B. echo gettype($remain);
C. echo type($remain);
D. echo explain($remain);
A. rmdir()
B. dir()
C. del()
D. dir_gone()
A. sleep() suspends operations and usleep() resumes them
B. sleep() accepts seconds and usleep() accepts milliseconds
C. sleep() works for the current process and usleep() works for all processes
D. sleep() can only be specified for the current user and usleep() can be specified for all users
A. list()
B. count()
C. number()
D. sizeof()
A. /var
B. /etc
C. /tmp
D. /usr
A. $_FILES
B. $_POST
C. $_GET
D. $_ENV
A. delete()
B. rid()
C. unlink()
D. close()
A. erase
B. fi
C. remove
D. unset
A. w
B. a
C. r+
D. w+
A. BROWSE_AGENT
B. BROWSER_TYPE
C. BROWSER_ENV
D. HTTP_USER_AGENT
A. -150
B. 150
C. 4250
D. 4400
E. 4550
F. "4400-150"
A. brackets [ ]
B. parentheses ( )
C. curly braces { }
D. quotation marks " "
A. Truth
B. Integer
C. Boolean
D. Float
A. $_FILES
B. $_POST
C. $_GET
D. $_ENV
A. URAND
B. END_NUMBER
C. ULIMIT
D. RAND_MAX
A. grep
B. ereg
C. psx
D. efgrp
A. True
B. False
C. Error
D. Null
A. arsort()
B. rev()
C. trosa()
D. zsort()
A. d
B. f
C. s
D. u
50.Which PHP conditional operator means not equal to?
A. !=
B. =!
C. <=>
D. <>
Answers
The closing tag used by PHP is ?>. Answer: C.
The PHP conditional operator of three equal signs (===) means the values are equal and of the same data type. Answer: C.
PHP variable names are case sensitive and variables do not need to be declared before they can be used. Answer: A and D.
The include instruction will create a warning, but allow the script to continue running when an error is encountered. Answer: C.
There are at least three ways to create comments in a PHP script, and <comment is not one of them. Answer: B.
The \n escape character in PHP renders a linefeed. Answer: A.
The global configuration file is php.ini.
The command $AU++; increments the variable by one ¨C changing it from 7 to 8. Answer: A.
The printf type specifier f is used for a floating point value. Answer: B.
The PHP logical operator to use to see if both a and b are true would be a && b. Answer: B.
The first entry is 0, the second is 1, and the numbers increment from there. Answer: D.
The srand() function must be called to send the random number generator before array_rand(). Answer: C.
The default order resulting from a sort utilizing asort() is alphabetic (A-Z) and lowest to highest (0-9). Answer: A and C.
Variable names cannot begin with a numeric character. Answer: B.
The opening tag used by PHP is <?php. Answer: A.
Curly braces are used to separate blocks of statements within a control structure. Answer: C.
The settype function can be used to assign a data type to a variable. Answer: C.
The REMOTE_ADDR HTTP variable contains the IP address of the machine making a request. Answer: D.
The POST method should be used for a form as described. Answer: A.
If the result is not a whole number, it is assigned the double data type If it is a whole number, integer is assigned. Answer: B.
The r+ mode of the fopen() function opens a file for reading or writing, maintains exiting content, and places the file pointer at the beginning of the file. Answer: C.
The copy() function can be used to copy a file. Answer: A.
To set a cookie to expire 24 hours from now, compute the number of seconds and use the time() function: $cookie_expire = time() +86400. Answer: C.
The semicolon character (;) is used as a statement terminator to indicate the end of a PHP command. Answer: D.
The command $days = array(); will initialize the $days array. Answer: B.
The file_exists() function can be used to see if a file by the given name is already in existence. Answer: D.
The value of $_COOKIE[user] is equal to what was set in the cookie. Answer: C.
The array_merge() function should be used to combine two or more existing arrays. Answer: B.
The function to use is session_start()
After opening a file with the fopen() function, fclose() is used to close the file pointer. Answer: A.
The gettype function can be used to show the data type for a variable. Answer: B.
The rmdir() function removes a directory from a file system. Answer: A.
sleep() accepts seconds and usleep() accepts milliseconds. Answer: B.
The sizeof() function can tell how many elements are in an array Answer: D.
Information about a session, by default, is configured in the PHP configuration file to be saved beneath /tmp. Answer: C.
$_ENV contains variables provided to a script by means of the server environment. Answer: D.
The unlink() function can be used to delete a file. Answer: C.
The unset function can be used to destroy a variable. Answer: D.
The "a" mode of the fopen() function opens a file for writing and places the file pointer at the end of the file. Answer: B.
The HTTP_USER_AGENT HTTP variable contains the browser type, and browser version, among other values. Answer: D.
This operation subtracts 150 from the existing value. Answer: C.
Parentheses are used to enclose conditional expressions. Answer: B.
The Boolean PHP data type can be either TRUE or FALSE. Answer: C.
$_FILES contains variables provided to a script by means of file uploads. Answer: A.
The RAND_MAX constant identifies the highest random number that a system can generate. Answer: D.
PHP provides support for POSIX through functions of the ereg class. Answer: B.
From a Boolean standpoint, every zero value in PHP is considered false. Answer: B.
The arsort() function places results in the opposite order of asort(). Answer: A.
The printf type specifier s is used for a string. Answer: C.
The != PHP conditional operator means not equal to. Answer: A.
Emmett Dulaney is the author of the several books on Linux/Unix and certification as well as a columnist for UnixReview.com. Emmett's blog can be found at: http://edulaney.blogspot.com, and he can be reached (and welcomes your comments) at: edulaney@insightbb.com.