PHP interview questions and answer 1

Source: Internet
Author: User
Echo is a language structure and has no return value. The print function is basically the same as echo. The difference is that print is a function and has a return value. print_r is a recursive print, which is used to output the PHP interview questions and answer 1 of the array object.

1. use PHP to print the previous day in the format of 22:21:21

// Echo date ('Y-m-d H: I: S', time ()-60*60*24
Echo date ("Y: m: d H: I: s", strtotime ("-1 day "));
?>

2. differences between echo (), print (), and print_r ()

Echo is a language structure and has no return value. The print function is basically the same as echo. The difference is that print is a function and has a return value. print_r is a recursive print that outputs array objects.

3. templates that can be used to split HTML and PHP

So much, in fact, PHP itself is a template engine, I used smarty, common also PHPLib, FastTemplate, Savant here has a template engine list: http://www.sitepoint.com/forums/showthread.php? T = 123769

4. how to implement PHP and JSP interaction?

The question is a bit vague. SOAP, XML_RPC, Socket function, and CURL can all achieve this. if PHP and Java are integrated, PHP has built-in this mechanism (if PHP and. NET integration. for example, $ foo = new Java ('Java. lang. system ');
5. what tools are used for version control?
CVS and SVN. SVN is known as the next generation of CVS and has powerful functions. However, CVS is a veteran with a high market share. I have been using SVN for a long time. The question is what tools are used. well, this may require the following answers: CVS Server on Apache as the Server, WinCVS as the client, and Subversion on Apache/DAV as the Server, tortoiseSVN as the client, or Subclipse as the client

6. how to implement string flip?

In fact, PHP itself has a string flip function: strrev (). try echo strrev ($ str). However, none of the three methods can solve the problem of Chinese string flip, errors may occur.

Function reverse ($ var)
{
$ Res = "";
For ($ I = 0, $ j = strlen ($ var); $ I <$ j; $ I ++)
{
$ Res = $ var [$ I]. $ res;
}
Return $ res;
}
$ Tmpvar = "wofang ";
$ Res = reverse ($ tmpvar );
Echo $ res;
?>

7. optimize the MYSQL database.

(1 ). in terms of database design, this is the responsibility of DBA and impact ect. a database with a good design structure should be de-normalized when necessary (I don't know what the Chinese translation is ), some data redundancy is allowed to avoid JOIN operations to improve query efficiency.
(2 ). in terms of system architecture design, the table is hashed, and massive data is hashed into several different tables. fast and Slow tables: only the latest data is retained. slow tables are archived in history. cluster, Master server Read & write, slave server read only, or N servers, each machine is a Master
(3). (1) and (2) better than PHP Programmer's requirements. it doesn't matter. check whether there is any less index.
(4 ). write efficient SQL statements to see if there are any inefficient SQL statements, such as generating full connections to Cartesian products, a large number of Group By and order by statements, and no limit. when necessary, encapsulate the database logic in the stored procedure of the DBMS. cache query results and explain each SQL statement
(5). all the results are required. only necessary data is obtained from the database, such as querying the number of comments of an article, select count (*)... Where article_id =? You can. do not select *... Where article_id =? Then msql_num_rows.
Send only required SQL statements. for example, if you modify only the title when modifying an article, update... Set title =? Where article_id =? Do not set content =? (Large text)
(6). use different storage engines when necessary. for example, InnoDB can reduce deadlocks. HEAP can increase the query speed by an order of magnitude.

8. Talk about transaction processing

Example of A transfer of USD 50 to B's account

9. how to achieve maximum load using apache + mysql + php

See 7

10. implement the method of intercepting Chinese strings without garbled characters.

Mb_substr ()

11.

$ Empty = '';
$ Null = NULL;
$ Bool = FALSE;
$ NotSet;
$ Array = array ();
// The following are the problems
$ A = "hello ";
$ B = & $;
Unset ($ B );
$ B = "world ";
// The answer is: hello
Echo $;
?>

12.

$ Empty = '';
$ Null = NULL;
$ Bool = FALSE;
$ NotSet;
$ Array = array ();
// The following are the problems
$ A = 1;
$ X = & $;
$ B = $ a ++;

// The following is the answer: 1
Echo $ B;
?>

13

$ Empty = '';
$ Null = NULL;
$ Bool = FALSE;
$ NotSet;
$ Array = array ();
// The following are the problems
$ X = empty ($ array );

// The following is the answer: true
Echo $ x? "True": "false ";
?>

14. use PHP to write the code that shows the client IP address and server IP address:

$ Ip = gethostbyname ("");
Echo $ ip;
?>

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.