PHP Interview Questions and answers (1)

Source: Internet
Author: User
Tags echo date

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

<? Php
// 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 with no returned values;

The print function is basically the same as the ECHO function. The difference is that print is a function with a return value;

Print_r is a recursive print used to output 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.

 

 

Code

<? Php
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. For example, you can query 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.

 

<? Php
$ 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.

 

<? Php
$ 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

 

<? Php
$ 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:

Print the Client IP Address: echo $ _ SERVER ['remote _ ADDR ']; or: getenv ('remote _ ADDR ');
Print Server IP: echo gethostbyname ("http://www.baidu.com /")

 

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.