PHP interview question 1 [redirected]_PHP tutorial

WBOY
Release: 2016-07-20 11:14:23
Original
851 people have browsed it

1. Use PHP to print the time of the previous day in the format of 2012-4-12 10:11:22

echo date("<span Y-n-d H:i:s</span>",strtotime("<span -1 day</span>"));
Copy after login

format character [a: am, pm lowercase, A:AM, PM uppercase g hour, 12-hour clock n month no preceding 0]
strtotime() is used as follows

<span <?</span>php
echo strtotime ("<span now</span>"), "<span \n</span>";
echo strtotime ("<span 10 September 2000</span>"), "<span \n</span>";
echo strtotime ("<span +1 day</span>"), "<span \n</span>";
echo strtotime ("<span +1 week</span>"), "<span \n</span>";
echo strtotime ("<span +1 week 2 days 4 hours 2 seconds</span>"), "<span \n</span>";
echo strtotime ("<span next Thursday</span>"), "<span \n</span>";
echo strtotime ("<span last Monday</span>"), "<span \n</span>";
<span ?></span> 
Copy after login

2.echo() print() print_f() difference

echo() is a php statement, so it has no return value and can print simple data.
print() is a function with a return value and can print simple data.
print_r() is a function that can print complex (mix) data.

3. Common PHP template engines

Smarty EasyTemplatePHP

4. Which tools can be used for version control

SVN CVS

5. Function to implement character flipping

strrev($str);

6. Common methods to optimize Mysql database

(1). In terms of database design, this is the responsibility of the DBA and Architect. Design a well-structured database. When necessary, denormalize it (English is this: denormalize, I don’t know the Chinese translation), allowing some Data redundancy avoids JOIN operations to improve query efficiency
(2). In terms of system architecture design, table hashing is used to hash massive data into several different tables. Fast and slow tables only retain the latest data. , the slow table is a historical archive. Cluster, master server Read & write, slave server read only, or N servers, each machine is Master for each other
(3). (1) and (2) exceed the requirements of PHP Programmer , would be better, it doesn’t matter. Check whether there are fewer indexes
(4). Write efficient SQL statements and see if there are any inefficient SQL statements, such as full joins that generate Cartesian products, a lot Group By and order by, no limit, etc. When necessary, encapsulate the database logic into the stored procedure on the DBMS side. Cache the query results and explain each SQL statement
(5). All the results are required, only from the database Get the necessary data, such as querying the number of comments on an article, select count(*) ... where article_id = ? That's it. Don't select * first ... where article_id = ? Then msql_num_rows.
Transmit only the necessary SQL statement, for example, when modifying an 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 different storage engines. For example, InnoDB can reduce deadlocks. HEAP can increase query speed by an order of magnitude.

7. Use PHP to obtain client IP and server IP

Client: $_SERVER[‘REMOTE_ADDR’] or getenv(‘REMOTE_ADDR’);

Server: gethostbyname(“baidu.com”);

8. Modify the session survival time

<?php
session_start(); 
// 保存一天 
$lifeTime = 24 * 3600; 
setcookie(session_name(), session_id(), time() + $lifeTime, "/"); 
?>
Copy after login
9. Write the SQL of the names of the ten people with the most posts, using the following table: members (id, username, posts, pass, email)
SELECT username 
FROM members
GROUP BY id 
ORDER BY count(posts) DESC 
LIMIT 0 , 10
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
10.简述如何得到当前执行脚本路径,包括所得到参数。
Copy after login
echo $_SERVER['SCRIPT_FILENAME']."?".$_SERVER['QUERY_STRING'];
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
11.mysql_fetch_row() 和mysql_fetch_array之间有什么区别?<br>mysql_fetch_row() 从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。每个结果的列储存在一个数组的单元中,偏移量从 0 开始。mysql_fetch_array() 是 mysql_fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
12.判断以下输出
Copy after login
 $str1 = null;
 $str2 = false;
 echo $str1==$str2 ? '<span 相等</span>' : '<span 不相等</span>';  //相等
 $str3 = '<span </span>';
 $str4 = 0;
 echo $str3==$str4 ? '<span 相等</span>' : '<span 不相等</span>';  //相等
 $str5 = 0;
 $str6 = '<span 0</span>';
 echo $str5===$str6 ? '<span 相等</span>' : '<span 不相等</span>';  //不相等
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
13.写出以下结果
Copy after login
<span <?</span>php
 $test = '<span aaaaaa</span>';
 $abc = & $test;
 unset($test);
 echo $abc;  <span //aaaaaa</span>
 <span ?></span>
Copy after login
When you unset a reference, you just break the binding between the variable name and the variable content. This does not mean that the variable contents are destroyed.

-----------未完待续-------------<br><br>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440291.htmlTechArticle1. Use PHP to print the time of the previous day in the format of 2012-4-12 10:11:22 echo date (" ",strtotime(" ")); format character [a: am, pm lower case, A: AM, PM upper case g hour, 12-hour format n month before no 0] strtoti...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template