PHP Programmer's written test and interview question sharing _php tutorial

Source: Internet
Author: User
Tags apd echo date install php php debugger print format
This article to the students summed up some of the PHP Programmer's written test and interview questions to share, if you are ready to interview PHP programmers do not first look at these topics oh.

Ordinary PHP Programmer pen Test
Tags: programmer PHP interview 2009-02-06 15:19
1. Print the previous day in PHP, the print format is May 10, 2007 22:21:21
2. The PHP code is as follows:
$a = "Hello";
$b =& $a;
Unset ($b);
$b = "World";
echo $a;
What is the result?
3. The PHP code is as follows:
$STR = "CD";
$ $str = "Landog";
$ $str. = "OK";
Echo $CD;
What is the result?
4. Write a piece of code in PHP, the implementation does not use the 3rd variable, Exchange $ A, $b value, $a, $b the initial value of their own.
5. Write the code in PHP, as required by the topic.
Table name User
ID Name Tel Content Date
1 313,333,663,366 College Graduates 2006-10-11
3 313,612,312,331 Bachelor's degrees 2006-10-15
5 020-5566556 Secondary School graduates 2006-10-15
4 Wang 513,521,212,125 College graduate 2006-12-25
2 .......
6 .......
Suppose the database connection is as follows:
$mysql _db=mysql_connect ("local", "Root", "pass");
@mysql_select_db ("db", $mysql _db);
(1) Check out all records with name equal to "Zhang San" and output.
(2) query by ID in ascending order, return only the first 3 records after sorting, and output.
6. Can javascript define a two-dimensional array, and if not, how can you solve it?
7. Assuming that a.html and b.html are under the same folder, the JavaScript implementation automatically jumps to b.html when the a.html is turned on for five seconds.
8. There are two files a.html and a.php, the code is as follows:
A.html




PHP Programmer Interview







A. php

$user _name = $_get[' user_name ');
$user _tel = $_get[' User_tel ');
$user _email = $_get[' User_email ');
$user _add = $_get[' User_add ');
echo "User name: $user _name
Tel: $user _tel
E-mail: $user _email
Address: $user _add
";
?>


(1) Please draw the a.html in the browser display.
(2) Enter in a.html: User name = Zhang San, phone = 020-38259977, mailbox =sunrising@srtek.cn, address = Guangzhou Sheng Rui, press the submit button after the output is?
9. Have you ever used a version control tool, if any, please describe it briefly.
10. Use CSS style sheets to define the visited hyperlink font size of 14pt, red.
11. Move any one number or symbol to set the equation, 102 = 101-1. Note: A move is not an exchange, and an equal sign cannot be separated.
12. Regular questions, 3, 1, 4, 1, 5, 9, 2, (), please follow the rules in parentheses to write the next expression.
13. Regular questions, 5, 8,-3, 5,-2, 3, 1, (), follow the rules in parentheses to write the next expression.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Answer:

1. Echo Date (' y-m-d h:i:s ', Strtotime ('-1 day '));

2. Hello

3. Landogok

4. $a = "ABCD";
$b = "1234";
echo "a= $a at initialization, b= $b
";
$a = $a. $b;
$b = strlen ($b);
$b = substr ($a, 0, (strlen ($a)-$b));
$a = substr ($a, strlen ($b));
echo "a= $a after swapping, b= $b
";

5. (1) $sql = "SELECT * from User where > $result = mysql_query ($sql);
while ($row = Mysql_fetch_array ($result, Mysql_assoc)) {
echo $row [' Name '];
}
(2) $sql = "SELECT * from the User ORDER by ID ASC limit 0,3";
$result = mysql_query ($sql);
while ($row = Mysql_fetch_array ($result, Mysql_assoc)) {
echo $row [' Name '];
}
6. JavaScript does not support two-dimensional array definitions and can be resolved with arr[0] = new Array ()

7. The JavaScript code is as follows:

8.

(1) as shown below:

Slightly. Because too lazy to insert the picture, if you want to see the results can save the code as an HTML file, and then open the browser to view.

(2) The output should be:

Name:

Phone:

Mailbox:

Address:

Because the form is submitted by post, it is read in a.php with a Get method, so no value is read.

9. Slightly

Ten. a:visited {font-size:14pt; color:red;}

11.102 = 101-1

12. The answer is 6, because ∏=3.1415926

13. The answer is 2, the rule is n= (n-2) –| (n-1) | , n>=3

1. In PHP, the name of the current script (not including the path and query string) is recorded in the predefined variable (1), whereas the previous page URL linked to the current page is recorded in the predefined variable (2) //This page address, Script_name can also: php/test.php
echo $_server[' php_self ']. "
";
URL address of the previous page linked to the current page:
echo $_server[' Http_referer ']. "
";
Other reference manuals: Language reference variables, pre-defined variables
The absolute path name of the pre-execute script: d:inetpubwwwrootphp est.php
echo $_server["Script_filename"]. "
";
Browsing current page user's IP address: 127.0.0.1
echo $_server["REMOTE_ADDR"]. "
";
(query) string (the first question mark in the URL?) Later content): id=1&bi=2
echo $_server["Query_string"]. "
";
The document root directory where the currently running script is located: D:inetpubwwwroot
echo $_server["Document_root"]. "
";
?>

2. Execution of program segments Will output __.
Reference manual "Language Reference" operator arithmetic operator% is modulo operation, output 0
Echo 8% (-2). "
";
Modulus $a% $b The result is negative when the $a is negative. Output-2
Echo ((-8)%3). "
";
Output 2
Echo (8% (-3)). "
";
?>
3. In HTTP 1.0, the meaning of status code 401 is ____; If you return a prompt for "file not found", the header function is available and the statement is ____.
Answer: 401 means unauthorized; header ("http/1.0 404 Not Found"); [see reference Manual, Function reference "HTTP function" header]
4. The function of array function arsort is ____; the function of statement error_reporting (2047) is ____.
A: Arsort: reverse-order an array and keep the index relationship error_reporting (2047) is: report all errors and warnings
5. Write a regular expression that js/vbs all the scripts on the Web page (that is, remove the script tag and its contents):
$script = "The following is not displayed:";
Echo preg_replace ("//si", "Replacement content", $script);
?>
6. Install PHP in the Apache module, in the file http.conf the first to dynamically load the PHP module with the statement ____,
Then use the statement ____ so that Apache will all the files with the extension php as PHP script.
Answer: LoadModule php5_module "C:/php/php5apache2.dll"; AddType application/x-httpd-php. php
See Catalogue of reference manuals II. Installation and Configuration "6. Installation under Windows system Apache 2.0.x under Microsoft windows
7. Statements include and require can include another file in the current file, the difference is ____; to avoid including the same file multiple times, you can replace them with a statement ____.
A: When handling failures, the include () generates a warning and require () causes a fatal error; Require_once ()/include_once ()
8. A parameter of a function cannot be a reference to a variable unless the ____ is set to ON in PHP.ini.
A: Allow_call_time_pass_reference Boolean: Whether to enable forcing arguments to be passed by reference when the function is called, see Appendix G of the Reference manual
The meaning of the left join in 9.SQL is __, if Tbl_user records the student's name and school Number (ID),
Tbl_score records the student (ID) and test scores (score) and exam subjects (subject) that the students (some of whom have been expelled after the exam), and the test subject (in the case of the students), to print out the names of each student and the corresponding score for each section, you can use the SQL statement ____.
Answer: Natural left outer connection
Create Database Phpinterview;
Use Phpinterview
CREATE TABLE Tbl_user
(
ID int NOT NULL,
Name varchar (NOT NULL),
Primary KEY (ID)
);
CREATE TABLE Tbl_score
(
ID int NOT NULL,
Score Dec (6,2) NOT NULL,
Subject varchar () NOT NULL
);
Insert into Tbl_user (ID, name) VALUES (1, ' Beimu ');
Insert into Tbl_user (ID, name) VALUES (2, ' Aihui ');
Insert into Tbl_score (ID, score, subject) VALUES (1, 90, ' language ');
Insert into Tbl_score (ID, score, subject) VALUES (1, 80, ' math ');
Insert into Tbl_score (ID, score, subject) VALUES (2, 86, ' math ');
Insert into Tbl_score (ID, score, subject) VALUES (2, 96, ' language ');
Select A.id,sum (b.score) as Sumscore
From Tbl_user A left join Tbl_score B
On A.id=b.id
GROUP BY a.ID
10. In PHP, Heredoc is a special string, and its end flag must ____
A: The line where the end identifier is located cannot contain any other characters except ";"
11. Write a function that can traverse all the files and subfolders under a folder.
function My_scandir ($dir)
{
$files =array ();
if (Is_dir ($dir))
{
if ($handle =opendir ($dir))
{
while (($file =readdir ($handle))!==false)
{
if ($file! = "." && $file! = "...")
{
if (Is_dir ($dir. " /". $file))
{
$files [$file]=my_scandir ($dir. " /". $file);
}
Else
{
$files []= $dir.] /". $file;
}
}
}
Closedir ($handle);
return $files;
}
}
}
Print_r (My_scandir ("D:program filesinternet Explorermui"));
?>


1. Which of the following sentences does not add John to the users array?
$users [] = ' John ';
John was successfully added to the array users.
Array_add ($users, ' John ');
There is no definition for function array_add ().
Array_push ($users, ' John ');
John was successfully added to the array users.
$users | | = ' John ';
Syntax error.
What are the differences between 2.sort (), Assort (), and Ksort ()? Under what circumstances are they used?
Sort ()
The index keys are renumbered from 0 to n-1 based on the values of the elements in the array, sorted in alphabetical order. It is mainly used to sort the array when the value of the array index key is unrelated to the itch.
Assort ()
PHP does not have a assort () function, so it may be a clerical error for asort ().
Asort ()
As with sort (), the elements of the array are arranged alphabetically, but all index keys are preserved, especially for associative arrays.
Ksort ()
Based on the values of the index keys in the array, the alphabetical order is especially suitable for associative arrays that want to sort the index keys.
3. What does the following code produce? Why?
$num = 10;
function Multiply () {
$num = $num *10;
}
Multiply ();
Echo $num;
The value of the $num is 10 because the function multiply () does not specify $num to be a global variable (for example, $num or $_globals[' num ').
4. What is the difference between a reference and a regular variable? How do I pass by reference? Under what circumstances do we need to do this?
The Reference transmits the address of the variable instead of its value, so when you change the value of a variable in a function, the entire application sees the new value of the variable.
A regular variable is passed to its value, and when the function changes the value of the variable, only the function sees the new value, and the other part of the application still sees the old value.

$myVariable = "its ' value";
Myfunction (& $myVariable); Transfer parameters with reference to reference transfer parameters to the function, you can make the function changes the variable, even after the function ends still retain the new value.
5. Some functions can be used to insert a function library in a script that is currently executing?
There are different answers to this question, and my first idea is to insert the PHP function library into the include (), include_once (), require (), require_once (), but think carefully again that the function library should also include COM objects and. NET function library, so our answer is to include com_load and Dotnet_load, and the next time someone mentions a "library", don't forget the two functions.
What is the difference between 6.foo () and @foo ()?
Foo () executes the function, and any interpretation errors, syntax errors, and execution errors will be displayed on the page.
@foo () will hide all of the above error messages when executing this function.
Many applications use @mysql_connect () and @mysql_query to hide MySQL error messages, which I think is a serious mistake, because mistakes shouldn't be hidden, you have to deal with them properly, and you can solve them if possible.
7. How do you debug your PHP application?
I don't often do this, I've tried many different debugging tools, and it's not easy to set up these tools in a Linux system. However, I will introduce a recently-noticed debugger.
php-advanced PHP Debugger or PHP-APD, the first step is to perform the following command installation:
Pear install APD After installation, start debugging by adding the following statement at the beginning of your script:
Apd_set_pprof_trace (); After execution, open the following file to review the execution log:
Apd.dumpdir
You can also use PPROFP to format the log.
Detailed information can be found in http://us.php.net/manual/en/ref.apd.php.
8. What is "= = ="? Try to give a "= =" is true but "= = =" is a false example.
"= = =" is to send back a Boolean value "false", you can also send back a Boolean value but can be assigned to a "false" function, Strpos () and Strrpos () is one of two examples.
The second part of the problem is a bit difficult to think of a "= =" is false, but "= = =" Is the real example is very easy, the opposite is very few examples. But I finally found the following example:
if (Strpos ("abc", "a") = = True) {//This part will never be executed because the position of "a" is 0, converted to a Boolean value of "false"}if ("Strpos (" abc "," a ") = = = True) {//This part will be executed because" = = = " The return value of the Guaranteed function Strpos () is not converted to a Boolean value.}
9. How would you define a category MyClass that has no member functions or attributes?
Class myclass{}
10. How do you produce a MyClass object?
$obj = new MyClass ();
11. How do I access the properties of this category and change its value within a category?
Using statements: $this->propertyname, for example:
Class myclass{private $propertyName; public function __construct () {$this->propertyname = "value";}}
What is the difference between 12.include and include_once? And what about require?
All three are used to insert other files in the script, depending on whether the Url_allow_fopen is approved, this file can be obtained from inside or outside the system. But there are also subtle differences between them:
Include (): This function allows you to insert the same file multiple times in a script, and if the file does not exist, it will issue a system warning and continue executing the script.
Include_once (): It is similar to the function of include (), as its name implies, the file will only be inserted once during the execution of the script.
Require (): similar to include (), it is also used to insert other files in the script, but if the file does not exist, it will issue a system warning, this warning will cause a fatal error causes the script to abort execution
13. Which of the following functions can turn a browser to another page?
Redir ()
This is not a PHP function and will cause execution errors.
Header ()
This is the correct answer, header () is used to insert the volume header data, can be used to turn the browser to another page, for example:
Header ("location:http://www.search-this.com/");
Location ()
This is not a PHP function and will cause execution errors.
Redirect ()
This is not a PHP function and will cause execution errors.

14. Which of the following functions can be used to open files for reading/writing?
Fget ()
This is not a PHP function and will cause execution errors.
File_open ()
This is not a PHP function and will cause execution errors.
fopen ()
This is the correct answer, fopen () can be used to open the file for reading/writing, in fact, there are many options for this function, see php.net for details.
Open_file ()
This is not a PHP function and will cause execution errors.
What is the difference between 15.mysql_fetch_row () and mysql_fetch_array ()?
Mysql_fetch_row () stores a column of the database in a zero-based array, the first column in the array index 0, the second column at index 1, and so on. MYSQL_FETCH_ASSOC () stores a column of the database in an associative array, the index of the array is the column name, for example, my database query back to "First_Name", "last_name", "e-mail" three fields, the index of the array is "first _name "," last_name "and" email ". Mysql_fetch_array () can send back the values of Mysql_fetch_row () and MYSQL_FETCH_ASSOC () at the same time.
16. What does the following code do for you? Please explain.
$date = ' 08/26/2003 ';p rint ereg_replace ("([0-9]+)/([0-9]+]/([0-9]+)", "[Url=file://2///1///3%22, $date]\2/\1/\3", $ Date[/url]);
This is the conversion of a date from MM/DD/YYYY format to dd/mm/yyyy format. A good friend of mine told me that this regular expression can be disassembled into the following statement, for such a simple representation is actually no need to disassemble, purely for the convenience of explanation:
Corresponds to one or more 0-9, followed by an oblique number $regexpression = "([0-9]+)/";//should be one or more 0-9, followed by another oblique number $regexpression. = "([0-9]+)/";//corresponds one or more 0-9$regexpression. = "([0-9]+)", as for [Url=file://2///1///3]\2/\1/\3[/url] is used to correspond to parentheses, the first pair of parentheses is the month, the second parenthesis corresponds to the date, The third parenthesis corresponds to the year.
17. Give you a line of text $string, how would you write a regular expression to remove the HTML tags in the $string?
First of all, PHP has built-in function strip_tags () to remove the HTML tags, why write their own formal expression? Well, as a question of the interview, I will answer:
$stringOfText = "

This is a test

"; $expression ="/< (. *?) > (. *?) /"; Echo preg_replace ($expression," [Url=file://2/]\2[/url] ", $stringOfText);//Someone says you can also use/(<[^>]*>)/$ expression = "/(<[^>]*>)/", Echo preg_replace ($expression, "", $stringOfText);
What is the difference between the 18.PHP and Perl resolution arrays and hash table methods?
That's why I keep telling people to choose the right programming language, so how can you answer this question if you only use one language? The problem is simple, and all Perl array variables start with @, such as @myArray, and PHP follows $ as the beginning of all variables, such as $myArray.
As for Perl, the hash list is used in%, for example%myhash,php, and is still used for $, for example $myHash.
19. How do you use PHP to solve the stateless nature of HTTP?
The two main choices are session and cookie. Using the session method is to add session_start () at the beginning of each page and then use the $_session hash table to store the session variable. As for cookies, you only need to remember one principle: Call the Set_cookie () function before outputting any text, and simply use the $_cookie hash list to access all cookie variables.
There is also a less reliable way to take advantage of the visitor's IP address, which has a specific risk.
What is 20.GD function library for?
This may be my favorite library since the PHP 4.3.0 version of GD is built into the PHP system. This library allows you to process and display a variety of formats, another common use is to make the document. Another option other than GD is ImageMagick, but the function library is not built into PHP and must be installed by the system administrator on the server.
21. Try to write a few ways to output a piece of HTML code.
Well, you can use any of the output statements in PHP, including Echo, print, printf, and most people use echo in the following example:
echo "My string $variable"; You can also use this method:
Echo << HTML tags in here as well.The END; Remarks must is on a line of its own, and can ' t contain any extra white space. END;
22.PHP better than Perl? Please discuss.
Let us not provoke a rhetoric for a simple question, as I have often said: "Choose the right language for your work, and don't give your work to language." "I personally think Perl is a great fit for command-line tools, and while it's good for Web applications, its real power can be fully played on the command line. Similarly, although PHP can be used in the context of the console, but the individual thinks it has a better performance on the Web application, PHP has a lot of functions designed specifically for Web applications, Perl seems to be the command of the design of the book.
Personally I like both languages, I used to use Perl, PHP and Java during college, but I used C # at work, but at home I spent a lot of time practicing PHP, Perl, Ruby (now learning) and Java, keeping my skills up-to-date. Many people ask me how C and C + +, whether they still have the opportunity to occupy a seat in my application, my answer is basically "no", my recent work is mainly focused on web development, although C and C + + can also be used to write Web pages, but they are not designed for this kind of work, "choose the right language for work", If I need to write a console app that shows the performance comparisons of bubble sort, quick sort, and merge sort, I'm sure I'll use C + +. If I need to write a photo album system, I'll use PHP or C # (I think the. NET language is more than the Web page in terms of making the user interface).

PHP Classic question (serial 4)
1 Please indicate the difference between the value of the PHP and the pass-through reference. When is the value passed?
A: Passing a value simply passes the value of a variable to another variable, and the reference indicates that the two points to the same place.
2 What is the function of error_reporting in PHP?
Answer: The error_reporting () function sets the error_reporting directive at runtime. PHP has many levels of errors, using the-this function sets a level for the duration (runtime) of your script.
3 Use regular expressions (Regular expression) to write a function that verifies that the e-mail message is formatted correctly.
A:
!--? php
if (isset ($_post[' action ') &&
$_post[' action ']== ' submitted ')
{
$email =$_post[' email '];
if (!preg_match ()/^ (?: w+.?) *w+@ (?: w+.?) *w+$/", $email))
{
echo
" e-mail detection failed ";
}
Else
{
echo
"e-mail detected successfully";
}
}
Else
{
?

Email detection






!--? php
}
?>

4 briefly describes how to get the current execution script path, including the obtained parameters.
Echo
"http://". $_server[' server_name '].$_server[' php_self ']. "?". $_server[' query_string '];
echo "http://". $_server[' http_host '].$_server[' Request_uri '];
?>

5 There is a one-dimensional array that stores the shaping data, write a function that arranges them in order from large to small. Requires high efficiency of execution. and explain how to improve the efficiency of execution. (The function must be implemented by itself and cannot use PHP functions)

Function Bubblesort (& $arr)
{
$cnt =count ($arr);
$flag = 1;
for ($i =0; $i < $cnt; $i + +)
{
if ($flag ==0)
{
Return
}
$flag = 0;
for ($j =0; $j < $cnt-$i-1; $j + +)
{
if ($arr [$j]> $arr [$j +1])
{
$tmp = $arr [$j];
$arr [$j]= $arr [$j +1];
$arr [$j +1]= $tmp;
$flag = 1;
}
}
}
}
$test =array (1,3,6,8,2,7);
Bubblesort ($test);
Var_dump ($test);
?>


6 Please give an example of how you can speed up page loading in your development process
A: To use the server resources to open, timely shut down the server resources, database Add index, the page can generate static, pictures and other large files separate server. Use the Code optimization tool.

http://www.bkjia.com/PHPjc/632660.html www.bkjia.com true http://www.bkjia.com/PHPjc/632660.html techarticle This article to the students summed up some of the PHP Programmer's written test and interview questions to share, if you are ready to interview PHP programmers do not first look at these topics oh. Ordinary PHP Programmer pen Question label ...

  • 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.