Accept? PHP ?? 1. use PHP to print the time format of the previous day in the format of 22:21:21
Date_default_timezone_set ('prc'); // Set the China time zone
Echo $ today = date ("Y-m-d h: I: s", (time ()-86400); // yesterday ??
2. differences between echo (), print (), and print_r ()
Echo is a PHP statement, print and print_r are functions, and the statement does not return values. the function can return values (even if it is not used)
Print can only print values of simple type variables (such as int and string)
Print_r can print values of complex types of variables (such as arrays and objects)
3. in PHP and C, there are two types of increment: Increment before increment and increment after increment. in essence, both increment before and increment increases the value of the variable, the effects on variables are the same. The difference is the incremental expression value. Increment first, write "+ + $ variable", and calculate the added value (PHP adds the variable value before reading the value of the variable, so it is called "increment first "). "$ Variable ++" is written, and the original value before the variable increments (PHP increases the value of the variable after reading the value of the variable, so it is called "post-increment ").
$ A = 1;
$ B = $ a ++;
$ B value? 1
3. what tools are used for version control?
SNV (Subversion), VSS (source code manager), etc.
4. how to implement string flip?
$ Luokuan = "ABCDEFG-tested -!!! May 1234 .. ";
$ N = mb_strlen ("$ luokuan ");
// Echo $ n;
$ Newluokuan = "";
For ($ I = $ n; $ I >=0; $ I --)
{
// $ Newluokuan. = substr ($ luokuan, $ I, 1 );
$ Newluokuan. = mb_substr ($ luokuan, $ I, 1, 'utf-8 ');
}
Echo $ newluokuan;
It is not an optimal algorithm without considering the combination of Chinese and English. you do not need to use the php library function to flip the string:
5. methods to optimize the MYSQL database
1. select the most suitable field attribute
2. use JOIN instead of Sub-Queries)
3. use UNION instead of creating a temporary table manually
4. Transactions
5. lock the table
6. use foreign keys
7. use indexes
6. templates that can be used to split HTML and PHP
Smarty, phplib, SmartTemplate...
7. Talk about transaction processing
It can control the synchronous submission and update of data generated by concurrent transactions. it is a lock concept. comit, rollback
8. how to achieve maximum load using apache + mysql + php
The question is too general: generate static html pages, squid reverse proxy, apache, mysql load balancing.
9. the method of intercepting Chinese strings without garbled characters is implemented.
First of all, we need to consider the character set problem. The next Chinese character occupies 3 bytes in UTF-8, while the next Chinese character occupies 2 bytes in GBK. you can write a function to process it yourself, and others write a lot. of course, you can also enable the mbstring extension library and use functions such as mb_substr () to intercept it.
10.
Var $ empty = '';
Var $ null = NULL;
Var $ bool = FALSE;
Var $ notSet;
Var $ array = array ();
$ A = "hello ";
$ B = & $;
Unset ($ B );
$ B = "world ";
What is $?
Hello, unset ($ B) only releases the alias relationship between $ B and $ a, and does not release $.
$ A = 1;
$ X = & $;
$ B = $ a ++;
What is $ B?
1. run $ B = $ a, $ a ++ first, so $ B is still 1.
$ X = empty ($ array );
What is $ x? True or false
True, $ array is an empty array
12. have you used version control software? What is the name of the version control software you use?
CVS: winCVS, a CVS client
VSS and Microsoft products are suitable for small and medium-sized projects. only single-person checkout is supported.
13. have you used the template engine? What is the name of the template engine that you use?
SMARTY is a template engine officially recommended by php. it is a compilation template, which is not the same as phplib and has powerful functions. it has over 30 tags and supports cache.
14. What methods do you use to solve the traffic issue for high-traffic websites?
Squid [reverse proxy], the best choice! Of course, if money is not a problem, increasing bandwidth is also a good choice!
15. use PHP to write the code that shows the client IP address and server IP address:
Echo $ _ SERVER ['remote _ ADDR '] // client ip address
Echo $ _ SERVER ['server _ ADDR '] // SERVER ip address
Interview Question 3
I. PHP/MySQL programming
1) in a content management system, the table message has the following fields:
Id article id
Title article title
Content
Category_id document Category id
Hits clicks
Create the table above and write MySQL statements
Create table message
(
Id int not null AUTO_INCREMENT primary key,
Title varchar (100 ),
Content varchar (1, 225 ),
Category_id int,
Hits int
)
Mssql? Sentence:
Create table message
(
Id INT identity (1, 1) not null primary key,
Title varchar (100 ),
[Content] varchar (225 ),
[Category_id] int,
Hits int
)
2) Similarly, the preceding content management system: the table comment records the user's reply content. The fields are as follows:
Comment_id reply id
Id document id, associated with the id in the message Table
Comment_content reply content
To query the database, you need to obtain a list of article titles in the following format and sort them by the number of replies.
Article id: number of replies in the document title
Use an SQL statement to complete the above query. if the article does not reply, the number of replies is displayed as 0.
Select. id,. title,. hits, if (ifnull (B. id, false), count (*), 0) as replay from message a left join comment B on. id = B. id
Group by a. id
Order by replay desc
3) in the preceding content management system, the table category stores the category information. The fields are as follows (3 points)
Category_id int (4) not null auto_increment;
Categroy_name varchar (40) not null;
When you enter an article, select an article category from the drop-down menu.
Write down how to implement this drop-down menu
Function categoryList ()
{
$ Result = mysql_query ("select category_id, categroy_name from category ")
Or die ("Invalid query:". mysql_error ());
Print (""N "); While ($ rowArray = mysql_fetch_array ($ result )) { Print ("". $ RowArray ['categroy _ name'].""N "); } Print ("");
}
3. PHP program
1) write the output results of the following program
$ B = 201;
$ C = 40;
$ A = $ B> $ c? 4: 5;
Echo $;
?>
$ A = 4
2) write the output results of the following program
$ Str = "cd ";
$ Str = "hotdog ";
$ Str. = "OK ";
Echo $ str;
?>
$ Str = "cd ";
IV,
1. The difference between passing a value in PHP and transferring a reference. When will the value be passed for reference?
Passing a value only transmits the value of a variable to another variable, and the reference indicates that the two points to the same place.
2. what is the role of error_reporting in PHP?
Set the error report level for the php script.
3. use a Regular Expression (Regular Expression) to write a function to verify that the email format is correct.
/*
Check whether the email address is an email address. the logical value is returned.
*/
Function CheckMailAdr ($ str ){
Return (eregi ("^ [_\. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + \.) + [a-z] {2, 3} $ ", $ str ));
}
4. briefly describe how to obtain the path of the script to be executed, including the obtained parameters.
Note: for example, there is a script www.domain.com, and the parameters passed to it include parameter 1, parameter 2, parameter 3 .... The method to pass the parameter may be GET or POST, so please write something like: http://www.domain.com/script.php? Result of parameter 1 = value 1 & parameter 2 = value 2...
The path of the script to be executed is ambiguous: if the absolute path of the script on the SERVER is obtained, use $ _ SERVER ['appl _ PHYSICAL_PATH ']. if the URL of the script is obtained, use
To obtain all parameters, use the following methods:
// Obtain post data
While (list ($ var, $ value) = each ($ HTTP_POST_VARS ))
{
Echo "$ var = $ value n ";
}
// Get the get data
While (list ($ var, $ value) = each ($ HTTP_GET_VARS ))
{
Echo "$ var = $ value n ";
}
5. there is a one-dimensional array that stores integer data. please write a function to sort them in ascending order. High execution efficiency is required. It also describes how to improve execution efficiency.
(This function must be implemented by yourself and cannot use php functions)
Can be sorted by bubble
Function BubbleSort ($ str)
{
For ($ I = 0; $ I
{
For ($ j = count ($ str)-2; $ j >=$ I; $ j --)
{
If ($ str [$ j + 1] <$ str [$ j])
{
$ Tmp = $ str [$ j + 1];
$ Str [$ j + 1] = $ str [$ j];
$ Str [$ j] = $ tmp;
}
}
}
Return $ str;
}
$ Str = array (, 9, 0, 11 );
Print_r (BubbleSort ($ str ));
?>
6. how can I speed up page loading during your development?
A. generate static HTML,
B. generate XML
C. use ZEND for acceleration
Interview Question 8
1-how to use javascript to determine whether a window has been blocked.
Script
Var result = window. open ("/somepage. aspx ");
If (result = null)
{
Alert ("The browser does not allow window pop-up ");
}
Script
2-write the session running mechanism
User A accesses Site Y. If Site Y executes session_start (); (the following assumes that session_start () always exists), A session_id is generated, this session id is generally saved to user A in the form of a cookie. set session in ini. use_only_cookies are set to 1, and the session id must be transmitted as a COOKIE .). At this time, the session id is represented as $ _ COOKIE ['phpsessid ']; (PHPSESSID can be modified using the session_name () function)
User A then accesses the session id ($ _ COOKIE ['phpsessid ']), which is sent to Site Y every time A accesses Y.
On Site Y, there is such a directory to save the actual data of the SESSION. Site Y receives the session id, obtains the association with the session data through the SESSION id, and returns the SESSION data.
3-which of the following functions are used to prevent SQL injection vulnerabilities.
Addslashes
4-write the SQL statement for the top 10 people with the most posts. use the following table:
Members (id, username, posts, pass, email)
SELECT username, count (*) as num FROM 'members 'group by username order by count (*) desc limit 10
5
You can write a program to find the maximum number.
$ Var1 = 1;
$ Var2 = 7;
$ Var3 = 8;
$ Max = $ var1> $ var2? $ Var1: $ var2;
$ Max = $ max> $ var3? $ Max: $ var3;
Echo $ max;
6) There is a table menu (mainmenu, submenu, url). please use recursion to write a tree menu and list all menus.
JS printing
7. Execution section
2
8. in HTTP 1.0, status code 401 indicates
401 (Unauthorized/Unauthorized)
401 (SC _UNAUTHORIZED) indicates that the client accesses the password-protected page when there is no valid identity information in the Authorization header. This response must contain a WWW-Authenticate authorization information header.
9. The role of the array function arsort is (); the role of the statement error_reporting (2047) is ().
Arsort-sorts arrays in reverse order and maintains the index relationship.
Error_reporting (2047) all ?? Warning
All errors and warnings, as supported, role t of level E_STRICT.
10. write the PHP5 permission control modifier (3 points)
Private protected public
11. write the php5 constructor and Destructor (2 points)
_ Construct _ destruct
12. what is the function used to obtain the total number of query result sets? (1 point)
Mysql_num_rows ($ res );
13. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable (1), and the URL linked to the current page is recorded in the predefined variable (2).
Echo $ _ SERVER ['php _ SELF ']; echo $ _ SERVER ["HTTP_REFERER"];
14. in HTTP 1.0, status code 401 indicates (4). if the "File Not Found" prompt is returned, the header function is available. The statement is (5 ).
(4) unauthorized (5) header ("HTTP/1.0 404 Not Found ");
15. write a regular expression to overwrite all JS/VBS scripts on the web page (that is, remove the script tag and its content): (9 ).
Echo preg_replace ("/ ]. *?>. *? <"/Script>/si", "", "dfedf