PHP Classic Interview questions: (constantly follow up on the supplement ...) )
1. The time format of the day before printing with PHP is 2009-02-10 22:21:21 (2 minutes)
echo Date (' y-m-d h:i:s ', Strtotime ('-1 day '));
Or
$yesterday = Time ()-(24 * 60 * 60);
Echo ' Today: '. Date (' y-m-d h:i:s '). " n ";
Echo ' Yesterday: '. Date (' y-m-d h:i:s ', $yesterday). " n ";
2, Echo (), print (), Print_r () difference (3 points)
ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)
Print only prints out values for simple type variables (such as int,string)
Print_r can print out values for complex type variables (such as arrays, objects)
echo--output one or more strings
3, the ability to make HTML and PHP separated from the use of the template (1 points)
Smarty,heyes Template class, etc.
5. What tools are used for version control? (1 points)
CVS and SVN,SVN, known as the next generation of CVS, are powerful, but CVS is a veteran and has a high market share. I have been using SVN, the topic is to ask what tool, uh, this may need to answer: CVS Server on Apache as the service side, Wincvs as a client; Subversion on Apache/dav do the server, TortoiseSVN do the client, or Subclipse do the client.
6, how to implement string rollover? (3 points)
Strrev ()
Or
$str = "ABCDEFG";
function Strrevv ($STR)
{
$len =strlen ($STR);
$newstr = ";
for ($i = $len; $i >=0; $i--)
{
$newstr. = $str {$i};
}
return $newstr;
}
$showstr = STRREVV ($STR);
echo $showstr. " <br> ";
---------------------------------------------------------------
7, optimize the MySQL database method. (4 points, more write more)
(1). Select the most applicable field property, you should set the field to not null as far as possible, so that in the future to execute the query, the database does not have to compare NULL values.
(2). Use connection (join) instead of subquery (sub-queries)
(3). Use Union (Union) instead of manually created temporary tables
(4). Use the LIKE keyword and wildcard characters sparingly
(5). Using Transactions and foreign keys
Or
(1). Database design Aspects, this is the responsibility of the DBA and architect, the design of a well-structured database, when necessary, to regularization (English is this: denormalize, Chinese translation into what I do not know), allow partial data redundancy, avoid join operation, to improve query efficiency
(2). System architecture design, the table hash, the huge amount of data scattered into a few different tables. Slow table, fast table only stay up-to-date data, slower table is a historical archive. Cluster, master server Read & write, from server read only, or n servers, each machine is master
(3). (1) and (2) Beyond PHP programmer requirements, will be better, will not matter. Check for fewer indexes
(4). Write efficient SQL statements to see if there are any inefficient SQL statements, such as the full connection of the generated Cartesian product, a large number of group by and order by, no limit, and so on. When necessary, the database logic is encapsulated in the DBMS side of the stored procedure. Cache query Results, Explain of each SQL statement
(5). All that is required is to fetch only the necessary data from the database, such as querying the number of comments for an article, select COUNT (*) ... where article_id = yes, don't select * ... where article_id = then Msql_n Um_rows. Send only the necessary SQL statements, such as when modifying the article, if the user only modified the title, then update ... set title = where article_id = Do not set content = (large text)
(6). When necessary, use a different storage engine. For example, InnoDB can reduce deadlocks. Heap can increase query speed by an order of magnitude
8, the meaning of PHP (give 1 points)
Hypertext Preprocessor
9. What is the function of MySQL to get the current time?, the function to format the date is (2 points)
Now (), Date_format (Date,format)
10, the implementation of the text string interception without garbled method. (3 points)
Mb_substr ()
---------------------------------------------------------------
11. Have you ever used version control software? If you have the name of the version control software you are using? (1 points)
TortoiseSVN-1.2.6 svn-1.2.3
12. Have you ever used a template engine? If you have the name of the template engine you are using? (1 points)
Smarty
13, please briefly describe your most proud of the development of the work (4 points)
This I think, because you are no longer a rookie, everyone has different ideas, ideas will follow their own knowledge and change.
14, for the large-volume website, what method do you use to solve the traffic problem? (4 points)
First, verify that the server hardware is sufficient to support current traffic
Second, optimize database access.
Third, prohibit the external hotlinking.
Four, control the download of large files.
V. Use different hosts to divert the main flow
VI, use traffic analysis statistics software.
-----------------------------------------------------------------
15. Use PHP to write the code showing client IP and server IP 1 points)
Show Client I
function Get_client_ip () {#
if (getenv (' http_client_ip ')) {
$client _ip = getenv (' http_client_ip ');
} elseif (getenv (' http_x_forwarded_for ')) {
$client _ip = getenv (' http_x_forwarded_for ');
} elseif (getenv (' remote_addr ')) {
$client _ip = getenv (' remote_addr ');
} else {
$client _ip = $HTTP _server_var[' remote_addr ');
}
return $client _ip;
}
Server IP
function Get_server_ip () {
if (Isset ($_server))
{
if ($_server[' server_addr ') $huoqu _ip=$_server[' server_addr '];
else $huoqu _ip=$_server[' local_addr '];
}
Else
{
$huoqu _ip=getenv (' server_addr ');
}
return $huoqu _ip;
}
16. What is the difference between statement include and require? To avoid including the same file multiple times, you can use (?) Statements instead of them? (2 points)
Require () and include () are exactly the same in all respects except how to deal with failures. The include () generates a warning and require () causes a fatal error.
In other words, if you want to stop processing the page when the file is lost, use require (). The include () is not the case and the script will continue to run.
Require () contains files in any case, and include () can optionally contain. www.
Instead of using
Include_once
Require_once
17, how to modify the session's survival time (1 points). (No test)
$savePath = "./session_save_dir/";
$lifeTime = 24 * 3600;
Session_save_path ($savePath);
Session_set_cookie_params ($lifeTime);
Session_Start ();
18, there is a web address, such as PHPMA home page: http://www.phpma.com, how to get its content? ($/min)
File_get_contents ($url)
19, in HTTP 1.0, the meaning of status code 401 is (?) If you return the prompt for "file not found", the header function is available with the statement (?);( 2 min)
Not authorized (Unauthorized)
Header ("http/1.0 403 Forbidden");
20, in PHP, Heredoc is a special string, its end flag must? (1 points)
In most languages, double quotation marks are strings, and single quotes are characters. In PHP, however, there are 3 types of string representations. That
Single quotation marks
Double quotes
Delimiter (Heredoc syntax)
See, a single quote can actually be used to represent a string. So what if I want to represent single quotes? Like most languages, use escape symbols. That is, the backslash "". So what's the difference between using single and double quotes? My point of view is that there is no much difference. The only difference is that double quotes can apply more escape characters.
Let's have a delimiter. Its syntax is "<<<". The usage is to provide an identifier after that, then provide the string after the identifier, and then provide the identifier after the string to end. For example:
<?php
$str = <<<eod
Hello, this is a example for HEREDOC Syntax.
Attention to it.
EOD;
Echo $str;
?> Note that the provided marker here is EOD, and the middle is the string.
<<<eod, there's no semicolon at the beginning.
The end flag must be shelf written, and a semicolon should end
21, talk about the advantages and disadvantages of asp,php,jsp (1 points)--(specifically, please search yourself)
22. Talk about MVC (1 points)
The MVC (Model/view/controller) pattern consists of three classes of objects. The model is the Application object, and view is its representation on the screen,
The controller defines how the user interface responds to user input.
Model-View-Controller (MVC) is a software design pattern appearing in the 80 's Smalltalk-80, which is now widely used.
(model) 1)
The model is the body part of the application. Models represent business data, or business logic.
2) Views (view)
A view is a part of the user interface in an application that is the interface that the user sees and interacts with.
3) Controllers (Controller)
Controller work is to control user interface data display and update model object state according to the user's input.
-------------------------------------------------------------------
23, write the number of the top 10 names of SQL, using the following table: Members (Id,username,posts,pass,email) (2 points)
Select Members.username
From members
Order BY posts DESC
Limit 10
24. Please indicate the difference between the value of the transfer and the reference in PHP. When is the value passed? (2 points)
Pass by value: Any changes to values within the function scope are ignored outside the function
Pass by reference: Any changes to values within a function can also reflect these changes outside of the function phpma
Pros and Cons: When passing by value, PHP must copy the value. This can be a costly operation, especially for large strings and objects.
Passing by reference does not require copying values, which is good for performance gains.
25. What is the function of error_reporting in PHP? (1 points)
Level used to configure the return of error messages
26. Please write a function to verify that the e-mail is in the correct format (2 points)
If the email address is valid, return True,else return False
function Validateemail ($email)
{
if (Eregi (' ^[_a-z0-9-]+ (. [ _a-z0-9-]+) *@[a-z0-9-]+ (. [ a-z0-9-]+) (*$ ', $email)) {
return true;
}else{
return false;
}
}
27. Describe how to get the current execution script path, including the obtained parameters. (2 points)
echo $_server[' Script_filename ']. "?". $_server[' query_string '];
28. How to modify the lifetime of the session. (1 points)
Setcookie ()
Or
Session_set_cookie_params ($lifeTime)
--------------------------------------------------------------------
29. JS Form Popup dialog function is? Get the input focus function? (2 points)
Alert (), Prompt (), confirm ()
Focus ()
30, JS's steering function is? How to introduce an external JS file? (2 points)
Window.location.href
<script type= "Text/javascript" src= "Prototype.js" ></script>
31. What is the difference between foo () and @foo ()? (1 points)
PHP supports an error control operator: @. Any error messages that may be generated by the expression are ignored until it is placed in a PHP expression.
Note: The @ operator is only valid for an expression. A simple rule for beginners is that if you can get a value from somewhere, you can precede it with the @ operator. For example, you can put it in variables, functions and include () calls, constants, and so forth. It cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach.
32. How do I declare a class with no methods and properties named "MyClass"? (1 points)
Class myclass{};
33. How to instantiate an object named "MyClass"? (1 points)
$newmyclass = new MyClass ();
34. How do you access and set the properties of a class? (2 points)
by-〉
$newmyclass = new MyClass ();
$temp = $newmyclass->testvalue;
$newmyclass->testvalue= "a";
35. What is the difference between mysql_fetch_row () and mysql_fetch_array? (1 points)
Mysql_fetch_row--Get a row from the result set as an enumerated array
Mysql_fetch_array--Gets a row from the result set as an associative array, or as a numeric array, or both
--------------------------------------------------------------------
36, what is the GD library for? (1 points)
The GD library provides a range of APIs for working with images, using the GD library to process images, or to create images.
The GD library on the site is often used to generate thumbnails or to add watermarks to images or generate reports on site data.
37. Point out some ways to enter HTML code in PHP. (1 points)
Print ("<br/>");
echo "<br/>";
38. Which of the following functions can open a file to read and write to a file? (1 points) (c)
(a) Fget () (b) File_open () (c) fopen () (d) Open_file ()
39. Which of the following options does not add John to the users array? (1 points) (b) (c) (d)
(a) $users [] = ' John ';
(b) Array_add ($users, ' John ');//This option is not sure, but the test does not have this function
(c) Array_push ($users, ' John ');
(d) $users | | = ' John ';
40, the following program will enter whether or not? (1 points)
<?php
$num = 10;
function Multiply () {
$num = $num * 10;
}
Multiply ();
Echo $num;
?>
No, local variables
41, use PHP to write a simple query, find out all the name "Zhang San" content and print out (2 points)
Table name User
Name Tel Content Date
Zhang 313,333,663,366 College Graduation 2006-10-11
Zhang 313,612,312,331 Bachelor's degree 2006-10-15
Zhang Si 021-55665566 secondary school 2006-10-15
Please complete the code according to the above topic:
$mysql _db=mysql_connect ("local", "Root", "pass");
@mysql_select_db ("db", $mysql _db);
$result =mysql_query ("select * from User where Name= ' Zhang San '");
while ($row =mysql_fetch_array ($result))
{
echo $row [' Name ']. $row [' Tel ']. $row [' Content ']. $row [' Date '];
echo "<br>";
}
42, how to use the following class, and explain what the following mean? (3)
Class test{
function Get_test ($num) {
$num =MD5 (MD5 ($num). " En ");
return $num;
}
}
Dual MD5 encryption
$testObject = new test ();
$encryption = $testObject->get_test ("Xiaotian_ls");
)
43. Write the format of the SQL statement: INSERT, UPDATE, delete (4 points)
Table name User
Name Tel Content Date
Zhang 313,333,663,366 College Graduation 2006-10-11
Zhang 313,612,312,331 Bachelor's degree 2006-10-15
Zhang Si 021-55665566 secondary school 2006-10-15
(a) A new record (Xiao Wang 13254748547 High school 2007-05-06) please add a SQL statement to the table
INSERT into User (' Name ', ' Tel ', ' Content ', ' Date ') VALUES (' Xiao Wang ', ' 13254748547 ', ' High School graduate ', ' 2007-05-06 ')
(b) Use an SQL statement to update the Zhang San time to the current system time
UPDATE User SET Date=date_format (now (), '%y-%m-%d ') WHERE name= ' Zhang San '
(c) Please write down all records named Zhang Xi
DELETE from User WHERE name= ' Zhang four '
44. Please write the meaning of the data type (int char varchar datetime text); What is the difference between varchar and char (2 points)
Char fixed-length character, insufficient length to fill with space; varchar does not seem to have this type,
37. MYSQ Self-increment type (usually the table ID field) must be set to (?) Field (1 points)
45, write out the following program output results (1 points)
<?
$b = 201;
$c = 40;
$a = $b > $c? 4:5;
echo $a;
?>
Answer: 4
46. Is there a function to detect whether a variable is set or not? is the function empty? (2 points)
Isset (); empty ();
-----------------------------------------------------------------------------
47. What is the function that gets the total number of query result sets? (1 points)
Mysql_fetch_array ();
48, $arr = Array (' James ', ' Tom ', ' Symfony '); Please print out the value of the first element (1 points)
echo $arr [' 0 '];
49. Separate the values of the array of 41 questions with ', ' and combine them into a string output (1 points)
$arr _im = Implode (",", $arr);
Print_r ($arr _im);
50, $a = ' abcdef '; Please remove the value of $ A and print out the first letter (1 points)
$a = ' abcdef ';
echo $a;
$a _exp = substr ($a, 0, 1);
echo "<br>";
echo $a _exp;
51. Can PHP connect to a database such as SQL Server/oracle? (1 points)
Of course
52. Please write out the PHP5 permission control modifier (3 points)
PHP5 introduces access adornments, which are placed before property and method declarations to control their visibility. The following three different access adornments are supported in PHP5:
1, the default is public, that is, when you do not specify an access adornment for properties and methods, it is the default. These public items can be accessed outside of the class class.
2. Private access modification means that the item being decorated can only be accessed in the class. If you don't use __get () and __set (), it's a good idea to add a private modifier to each attribute. You can also add private adornments to methods, such as some functions that are only used in classes. Private-decorated items cannot be inherited (more details are mentioned later in this chapter).
3. Protected (Protected) modified items can be accessed in the class and its subclasses. The same more detail will be mentioned in the later sections of this chapter. For the time being, protected can be seen as a modification between public and private.
53. Please write the PhP5 constructor and destructor (2 points)
If you declare a function in a class named __construct, the function will be treated as a constructor and executed when an object instance is created. Clearly, __ is an underscore of two. Just like any other function, constructors may have parameters or default values. You can define a class to create an object and put its properties all in one statement (statement).
You can also define a function called __destruct, and PHP will call this function before the object is destroyed. It is called a destructor.
------------------------------------------------------------------------------
54, the following please complete with phpMyAdmin-(no test)
(a) Create a press release system with the following fields (3 points) for the table named message
ID Article ID
Title of title article
Content article contents
CATEGORY_ID article Category ID
Hits Click Volume
(ii) The same press release system: Table comment Record the user reply content, the field is as follows (4 points)
comment_id Reply ID
ID article ID, ID in the associated message table
Comment_content Reply Content
Now by querying the database need to get the following format of the article title list, and according to the number of replies sorted, reply to the highest ranked in the front
Article ID article title click Reply Quantity
Use an SQL statement to complete the above query, if the article does not reply to the number of replies displayed as 0
Select Message.id,message.title, Message.hits sum (select COUNT (0) from comment where message.id=comment.id) as Comsums fr Om message Comment order by Comsums;
(c) The above Content management system, table category to save the classification information, the field is as follows (3 points)
category_id Int (4) not NULL auto_increment;
Categroy_name varchar (+) not null;
When a user enters an article, select the article category by selecting the drop-down menu
Write how to implement this drop-down menu
The following ADODB are used
$CNN =& newadoconnection (' MySQL ');
$CNN, Connect ($db _hostspec, $db _username, $db _password, $db _database);
Setfetchmode, $CNN (ADODB_FETCH_ASSOC);
if (! $cnn) Message ("Unable to connect to database $db _database");
$sql = "SELECT * from ' category ' WHERE 1;
$rst =& $cnn, Execute ($sql);
if (! $rst) Die ($CNN, errormsg ());
$arr _categroy = $rst, GetArray ();
<select>
<?php foreach ($arr _categroy as $i = $row):?>
<option value= "<?php echo $i;? > "><?php echo $row;? ></option>
<?php Endforeach;?>
</select>
PHP Face question Finishing