1. Differences between echo(), print(), and print_r()
echo() is a language construct with no return value
print() is functionally basically the same as echo() and is also a language construct, but unlike echo, print has a return value and always returns 1
print_r is a recursive print used to output arrays and objects
2. What is the difference between the include and require statements? To avoid including the same file multiple times, which statement can be used instead?
When an exception occurs, include generates a warning, while require generates a fatal error
include_once()/require_once()
3. How to modify the lifetime of a SESSION
// Save for one day
$lifetime = 24 * 3600;
session_set_cookie_params($lifetime);
session_start();
4. Write an SQL statement to get the names of the top ten users with the most posts, using the following table: members(id,username,posts,pass,email)
SELECT name FROM members ORDER BY posts,id DESC limit 0,10
5. Explain the difference between passing by value and passing by reference in PHP. When should you pass by value, and when should you pass by reference?
Pass by value: Variables are assigned by value by default. When the value of one variable is assigned to another variable, changing the value of one will not affect the other.
Pass by reference: Modifying the new variable will affect the original variable, and vice versa.
When passing by value, the value must be copied, which incurs some performance overhead for large strings and objects. Passing by reference does not require copying the value, which is beneficial for performance improvement
6. What is the purpose of the error_reporting function in PHP?
It sets the error reporting level during script execution
7. Write a function to verify whether the format of an email address is correct
preg_match(“/^(?:w+.?)*w+@(?:w+.?)*w+$/”,$email);
8. What are the JS functions that pop up a dialog box in a form? What is the function to get input focus?
alert(), prompt(), confirm()
focus()
9. What is the JS redirect function? How do you include an external JS file?
window.location.href
<srcipt type=”text/javascript” src=”*.js”></srcipt>
10. Use jQuery to get the element with the class gb2 from the following document
$(‘.gb2’)
11. What is the difference between mysql_fetch_row() and mysql_fetch_array()?
mysql_fetch_row() fetches a row from the result set as an enumerated array
mysql_fetch_array() fetches a row from the result set as an associative array, a numeric array, or both
12. Which of the following functions can open a file for reading and writing?
(a)fget()
(b)file_open()
(c)fopen()
(d)open_file()
(c)
13. Which of the following options does not add ‘john’ to the users array?
(a)$users[] = ‘john’;
(b)array_add($users,’john’);
(c)array_push($users,’john’);
(d)$users ||= ‘john’;
(b) and (d) both fail to add it
14. What will the following program output?
<?php
$num = 10;
function multiply() {
$num = $num * 10;
}
multiply();
echo $num;
?>
10
15. Write a simple query in PHP to find all records with the name “张三” and print them out
Table name User
Name Tel Content Date
张三 13333663366 大专毕业 2006-10-11
张三 13612312331 大专毕业 2006-10-15
张四 021-55665566 大专毕业 2006-10-15
Please complete the code based on the above:
<?php
$mysql_db = mysql_connect(“localhost”,”root”,”pass”);
@mysql_select_db(“DB”,$mysql_db);
$sql = “SELECT Name,Tel,Content,Date FROM User WHERE Name=’张三’”;
$result = mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
echo $row[‘Name’].$row[‘Tel’].$row[‘Content’].$row[‘Date’];
}
?>
16. How do you use the following class, and explain what it means?
<?php
class test {
function Get_test($num) {
$num = md5(md5($num).”En”);
return $num;
}
}
$test = new test();
$num = 1;
$test->Get_test($num);
?>
17. Write the format for SQL statements: insert, update, delete
Table name User
Name Tel Content Date
张三 13333663366 大专毕业 2006-10-11
张三 13612312331 本科毕业 2006-10-15
张四 021-55665566 中专毕业 2006-10-15
(a) There is a new record (小王 13254748547 高中毕业 2007-05-06). Use an SQL statement to add it to the table
(b) Use an SQL statement to update 张三’s time to the current system time
(c) Write a statement to delete all records named 张四
(a)
INSERT INTO User(‘Name’,’Tel’,’Content’,’Date’) VALUES(‘小王’,’13254748547′,’高中毕业’,’2007-05-06′)
(b)
UPDATE User SET Date=DATE_FORMAT(NOW(),’%Y-%m-%d’) WHERE Name=’张三’
(c)
DELETE FROM User WHERE Name=’张四’
18. Explain the meaning of the data types (int char varchar datetime text); what is the difference between char and varchar?
int is a numeric type, char is a fixed-length string, varchar is a variable-length string, datetime is a date/time type combining date and time, text is a text string
The length of char is fixed to the length declared when the table is created. When saving a char value, it is padded with spaces on the right to reach the specified length. varchar is a variable-length string, and varchar values are not padded when saved.
19. A MySQL auto-increment type (usually the table’s ID field) must be set as a (?) field
primary key
20. Write the output of the following program
<?php
$b = 201;
$c = 40;
$a = $b>$c?4:5;
echo $a;
?>
4
21. What function checks if a variable is set? What function checks if it is empty?
isset()
empty()
22. What function gets the total number of rows in a query result set?
mysql_num_rows($result);
23. $arr = array(‘james’,’tom’,’symfony’);
(1) Print the value of the first element
(2) Join the array values with ‘,’ and output them as a string
(1)
<?php
$arr = array(‘james’,’tom’,’symfony’);
echo $arr[0];
?>
(2)
<?php
$arr = array(‘james’,’tom’,’symfony’);
echo implode(‘,’,$arr);
?>
24. $a = ‘abcdef’; Extract the value of $a and print the first letter
<?php
$a = ‘abcdef’;
echo $a{0};
?>
25. Write the PHP 5 access control modifiers
public, protected, private
26. Write the constructor and destructor for PHP 5
_construct
_destruct
27. Have you used version control software? If so, what is the name of the version control software you use?
Yes, such as SVN, Git, etc.
28. Have you used a template engine? If so, what is the name of the template engine you use?
Yes, such as Smarty, Ease Template, etc.
29. For high-traffic websites, what methods do you use to solve traffic volume issues?
1. Use traffic analysis and statistics software;
2. Confirm whether the server hardware is sufficient to support the current traffic;
3. Optimize database access;
4. Prevent external hotlinking;
5. Control the downloading of large files;
6. Use different hosts to divert the main traffic;
30. Discuss your understanding of MVC.
The goal of MVC is to separate business logic from user interface considerations. In MVC, the model represents information (data) and business rules; the view contains user interface elements, such as text, forms, etc.; the controller manages the communication between the model and the view.
31. Have you used Eclipse as a PHP development IDE? If so, name at least three debug shortcuts and their corresponding functions
32. Write a function, as efficiently as possible, to traverse all subfolders in the ‘home’ folder and return an array of subfolder names
<?php
/**
* Traverse a directory, store results in an array, supports PHP 4 and above. In PHP 5 and later, the scandir() function can be used instead of a while loop
* @param string $dir
* @return array
*/
function my_scandir($dir) {
$files = array();
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if ($file != “..” && $file != “.”) {
if (is_dir($dir . “/” . $file)) {
$files[$file] = my_scandir($dir . “/” . $file);
} else {
$files[] = $file;
}
}
}
closedir($handle);
return $files;
}
}
function my_scandir1($dir){
$files = array();
$dir_list = scandir($dir);
foreach ($dir_list as $file) {
if ($file != “..” && $file != “.”) {
if (is_dir($dir . “/” . $file)) {
$files[$file] = my_scandir1($dir . “/” . $file);
} else {
$files[] = $file;
}
}
}
return $files;
}
$result = my_scandir(‘E:\php\home’);
// $result1 = my_scandir1(‘E:\php\home’);
print_r($result);
?>
33. Describe in detail the meaning of the following code snippet (Note: it does not achieve the expected result; this is the original code)
<?php
$text = ‘快来加入我们的 !企业 社会化讨论组吧’;
// preg_replace(‘/(^|[\s\.\,\:\;]+)!([A-Za-z0-9\x80-\xff]{1,64})/e’,”‘\\1!’.common_link($id, ‘\\2’)”, $text);
?>
Performs a regular expression search and replace, removing punctuation from $text
34. Write code according to the requirements
(1) Declare a Cat object that has one public property: name; and two behaviors: walk(), talk()
(2) Declare a MyCat object that inherits from the Cat object
(3) MyCat has one public property: color
(4) Instantiate a MyCat object and assign the value ‘blank’ to the color property
(5) Execute MyCat’s talk method and print the value of the current MyCat object’s color property
<?php
// (1)
class Cat {
public $name;
function walk() {
}
function talk() {
}
}
// (2)(3)
class MyCat extends Cat {
public $color;
}
// (4)(5)
$mycat = new MyCat();
$mycat->color = ‘black’;
$mycat->talk();
print($mycat->color);
?>
1. What is a BOM, and what are its hazards?
BOM (Byte Order Mark) is a standard mark used in UTF encoding schemes to identify the encoding
Because of the BOM, PHP mistakenly thinks that text content has already been output, which affects page rendering
2. If the HTML webpage encoding written by the front-end engineer is gb2312, while the database and PHP file encoding is UTF-8, how can this issue be quickly resolved?
Quick fix: The PHP file must output a header: header(“Content-type:text/html;charset=gb2312”), and the PHP file’s own encoding must be converted to gb2312
mysql_query(“SET NAMES GBK”);
Thorough fix: Convert the HTML webpage to utf-8, unifying everything to utf-8
3. <!– Replace [img]http://www.leshisz.com/themes/default/images/index/ad/ad-stay-tuned.png[/img] with <img alt=”敬请期待” src=”http://www.leshisz.com/themes/default/images/index/ad/ad-stay-tuned.png” height=”288″ width=”500″></img>, UBB code –>
<?php
$str = '[img]http://www.leshisz.com/themes/default/images/index/ad/ad-stay-tuned.png[/img]';
//<img alt="敬请期待" src="http://www.leshisz.com/themes/default/images/index/ad/ad-stay-tuned.png" height="288" width="500"></img>
$img = str_replace('[img]', '<img alt="敬请期待" src="', $str);
$img = str_replace('[/img]', '" height="288" width="500"></img>', $img);
echo $img;
?>
4. For MySQL performance inspection, what should be added before an SQL statement?
If you place the keyword EXPLAIN before a SELECT statement, MySQL will explain how it processes the SELECT, providing information about the order in which tables are joined.
5. Different users may share the same IP. You need to count the number of distinct IPs and sort them in descending order
Table name User
id Name Tel Ip Date
1 张三 13333663366 01.33.22.33 2006-10-11
2 张三 13612312331 03.22.33.33 2006-10-15
3 张四 021-55665566 01.33.22.33 2006-10-15
SELECT count(ip) AS count FROM user GROUP BY id ORDER BY count DESC
6. Print out the current form’s $_POST and $_GET
<form method=”post” action=”2.php?s=1&a=2″>
<input type=”hidden” name=”var[]” value=”aa”>
<input type=”hidden” name=”var[]” value=”bb”>
<input type=”checkbox” name=”checkbox” value=”cc”>
<input type=”submit” name=”submit” value=”submit”>
</form>
$_POST = array (
var => Array (
0 => ‘aa’,
1 => ‘bb’
)
submit => ‘submit’
)
$_GET = array (
s => 1,
a => 2
)
(I) Basic Questions
1. Write the output of this program in the browser:
<?php
$str1=null;
$str2=false;
echo $str1==$str2?’相等’:’不相等’;
$str3=”;
$str4=0;
echo $str3==$str4?’相等’:’不相等’;
$str5=0;
$str6=’0′;
echo $str5===$str6?’相等’:’不相等’;
?>
相等 相等 不相等
2. Write the output of this program in the browser:
<?php
$a1=null;
$a2=false;
$a3=0;
$a4=”;
$a5=’0′;
$a6=’null’;
$a7=array();
$a8=array(array());
echo empty($a1)?’true’:’false’;echo'</br>’;
echo empty($a2)?’true’:’false’;echo'</br>’;
echo empty($a3)?’true’:’false’;echo'</br>’;
echo empty($a4)?’true’:’false’;echo'</br>’;
echo empty($a5)?’true’:’false’;echo'</br>’;
echo empty($a6)?’true’:’false’;echo'</br>’;
echo empty($a7)?’true’:’false’;echo'</br>’;
echo empty($a8)?’true’:’false’;
?>
true
true
true
true
true
false
true
false
3. Write the output of this program in the browser:
<?php
$str=”a”;
$$str=”net”;
$$str.=”work”;
$b=&$a;
unset($b);
$b=”hello wolrd”;
echo $a;
echo “</br>”;
echo $b;
?>
network
hello wolrd
4. Write the output of this program in the browser:
<?php
$a=99;
$b=100;
$c=10;
++$a>$b–?$c++:$c+=$b;
echo $a.”</br>”.$b.”</br>”.$c;
?>
100
99
109
5. Use PHP to print the previous day’s time in the format 2004-4-8 11:11:11
<?php
print_r(date(‘Y-n-j H:i:s’),strtotime(‘-1 day’));
?>
6. Write PHP code to display the client IP and server IP
<?php
echo $_SERVER[‘REMOTE_ADDR’];
echo $_SERVER[‘SERVER_ADDR’];
?>
7. List several methods for passing values between PHP pages
GET POST COOKIE
8. Swap the values of two existing variables directly without using a new variable
<?php
$a = 1;
$b = 2;
// Assign values from an array to some variables
list($b, $a) = array($a, $b);
?>
10. List several common PHP frameworks
Yii, thinkphp, Zend Framework, CakePHP
(II) Algorithm and Programming Questions
1. How to reverse a string
<?php
$a = ‘abcde’;
$b = ”;
for ($i=strlen($a)-1;$i>=0;$i–) {
$b .= $a{$i};
}
// Or
$c = strrev($a);
?>
2. Write a bubble sort algorithm
<?php
$arr = array(45,56,67,32,33,23,37,455,223,223,23);
for ($i=1;$i<count($arr);$i++) {
for ($j=count($arr)-1;$j>=$i;$j–) {
if ($arr[$j]<$arr[$j-1]) {
$temp = $arr[$j-1];
$arr[$j-1] = $arr[$j];
$arr[$j] = $temp;
}
}
}
?>
4. Given a table menu(parent,clildren,url), use recursion to write a tree menu that lists all menus
<?php
// parent为null,表示无父级,为一级菜单,clildren为其本身ID
$menu = array(
0 => array(null,1,url1),
1 => array(null,2,url2),
2 => array(1,3,url3),
3 => array(1,4,url4),
4 => array(2,5,url5),
5 => array(1,6,url6),
6 => array(4,7,url7),
7 => array(5,8,url8)
);
function menu($menu) {
$menu1 = array();
$menu2 = array();
// 一级菜单
foreach ($menu as $k => $v) {
if ($v[0] == null) {
$menu1[$v[1]] = $v;
unset($menu[$k]);
}
}
// 二级菜单
foreach ($menu as $k => $v) {
foreach ($menu1 as $k1 => $v1) {
if ($v[0] == $v1[1]) {
$menu1[$v1[1]]['clildren'][$v[1]] = $v;
unset($menu[$k]);
}
}
}
// 三级菜单
foreach ($menu as $k => $v) {
foreach ($menu1 as $k1 => $v1) {
if ($v1['clildren']) {
foreach ($v1['clildren'] as $k2 => $v2) {
if ($v[0] == $v2[1]) {
$menu1[$v1[1]]['clildren'][$v2[1]]['clildren'][$v[1]] = $v;
unset($menu[$k]);
}
}
}
}
}
return $menu1;
}
$menu3 = menu($menu);
print_r($menu3);
?>
(III) Comprehensive Q&A
3. Discuss transaction processing
What is a transaction? A transaction is essentially a unit of operation in which all operations either all succeed or all fail. If all operations succeed, the transaction is committed. Even if one operation fails, the transaction will roll back, and all affected data will be restored to its previous state.
4. What is the difference between GET and POST form submissions? How to achieve partial updates on the client side to interact with the server?
The GET method is the default method for submitting form data. It passes user data via URL requests. The amount of data transmitted by the GET method is very small, generally limited to around 2KB, but its execution efficiency is higher than the POST method. Because the data transmitted using the GET method is transparent to the user, it may introduce certain security issues. The POST method uses the HTTP POST mechanism to pass the data within the form to the server side via the HTML header. Unlike the GET method, the data passed by the POST method is invisible to the user, and the POST method can handle a much larger amount of data.
ajax
7. What is the principle of SQL injection, and how to prevent it?
SQL injection occurs when an attacker inserts SQL commands into web form submissions, input domains, or page request query strings, ultimately tricking the backend database into executing malicious SQL commands. Based on the results returned by the program, the attacker obtains certain data they wish to know.
Prevention methods:
Programmers should improve their technical skills and use standardized development practices;
Check the legitimacy of data before submitting it to the server for processing;
Encapsulate information submitted by the client;
Replace or remove sensitive characters and strings;
Do not return error messages to the user;
Use non-conventional encryption for sensitive data to prevent information leakage;
Strengthen database inspections and web server log checks;
Do not build SQL queries using string concatenation; instead, use SQL variables, because variables are not executable scripts;
8. Given the following two table structures, user table: ‘user’, user group table: ‘group’:
// Table names and field names cannot be enclosed in single quotes, and ‘group’ cannot be used, so the field ‘group’ is changed to ‘groupid’, and the table ‘group’ is changed to ‘groups’
CREATE TABLE user(
id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
username varchar(50) DEFAULT NULL,
age int(11) DEFAULT NULL,
level int(11) DEFAULT NULL,
groupid int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE groups(
groupid int(11) NOT NULL AUTO_INCREMENT,
groupname varchar(50) DEFAULT NULL,
grouplevel int(11) DEFAULT NULL,
PRIMARY KEY(groupid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Write SQL query statements to query:
(1) Get the user IDs of users aged between 20-50, whose last name is “张”, and whose level is less than 5; sort in descending order
SELECT id FROM user WHERE (age BETWEEN 20 AND 50) AND username LIKE ‘张%’ AND level<5 ORDER BY age,id DESC
(2) Get the names of all users older than 25 whose user group name is “技术部” and whose user group level is between 2-10
SELECT username FROM user AS u LEFT OUTER JOIN groups AS g ON u.groupid=g.groupid WHERE g.groupname=’技术部’ AND (g.grouplevel BETWEEN 2 AND 10) AND u.age>25
(3) Get the number of members belonging to the “技术部” user group in the age ranges 1-10, 11-20, 21-30, and 31 and above, displaying the counts corresponding to each range
SELECT COUNT(id) FROM user AS u
LEFT OUTER JOIN groups AS g ON u.groupid=g.groupid
WHERE (g.groupname=’技术部’) AND (u.age between 1 AND 10)
Just repeat this 3 more times
(IV) Socket Operations
1. List a few common operation functions for PHP Socket communication, what are their respective purposes, and how do you check for exceptions in each operation?
getprotobyname() Gets the protocol number associated with the protocol name
socket_create() Creates a socket (communication endpoint)
socket_bind() Binds a name to a socket
2. Write a simple Socket request program, specifying the IP as: 192.168.0.1, the port as: 9501, the content to send: 12345, and the protocol as TCP
<?php
//确保在连接客户端时不会超时
set_time_limit(0);
$ip = '192.168.0.1';
$port = 9501;
/*
+-------------------------------
* @socket通信整个过程
+-------------------------------
* @socket_create
* @socket_bind
* @socket_listen
* @socket_accept
* @socket_read
* @socket_write
* @socket_close
+--------------------------------
*/
/*---------------- 以下操作都是手册上的 -------------------*/
if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0) {
echo "socket_create() 失败的原因是:".socket_strerror($sock)."\n";
}
if(($ret = socket_bind($sock,$ip,$port)) < 0) {
echo "socket_bind() 失败的原因是:".socket_strerror($ret)."\n";
}
if(($ret = socket_listen($sock,4)) < 0) {
echo "socket_listen() 失败的原因是:".socket_strerror($ret)."\n";
}
$count = 0;
do {
if (($msgsock = socket_accept($sock)) < 0) { echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n"; break; } else { //发到客户端 $msg ="测试成功!\n"; socket_write($msgsock, $msg, strlen($msg)); echo "测试成功了啊\n"; $buf = socket_read($msgsock,8192); $talkback = "收到的信息:$buf\n"; echo $talkback; if(++$count >= 5){
break;
};
}
//echo $buf;
socket_close($msgsock);
} while (true);
socket_close($sock);
?><?php
error_reporting(E_ALL);
set_time_limit(0);
echo "
<h2>TCP/IP Connection</h2>
\n";
$port = 9501;
$ip = "192.168.0.1";
/*
+-------------------------------
* @socket连接整个过程
+-------------------------------
* @socket_create
* @socket_connect
* @socket_write
* @socket_read
* @socket_close
+--------------------------------
*/
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}else {
echo "OK.\n";
}
echo "试图连接 '$ip' 端口 '$port'...\n";
$result = socket_connect($socket, $ip, $port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}else {
echo "连接OK\n";
}
$in = "12345\r\n";
$out = '';
if(!socket_write($socket, $in, strlen($in))) {
echo "socket_write() failed: reason: " . socket_strerror($socket) . "\n";
}else {
echo "发送到服务器信息成功!\n";
echo "发送的内容为:<font color='red'>$in</font>
";
}
while($out = socket_read($socket, 8192)) {
echo "接收服务器回传信息成功!\n";
echo "接受的内容为:",$out;
}
echo "关闭SOCKET...\n";
socket_close($socket);
echo "关闭OK\n";
?>
1. In your own way, write a calculator that includes functions like + – * /, etc. Use your technical skills to make the code quality as high as possible
<?php
// 第1个参数为计算符号,第2、3个参数为需要计算的值
function calculate($symbol, $v1, $v2) {
if (is_numeric($v1) && is_numeric($v2)) {
switch ($symbol) {
case '+':
return $v1+$v2;
break;
case '-':
return $v1-$v2;
break;
case '*':
return $v1*$v2;
break;
case '/':
return $v1/$v2;
break;
default:
return '计算符号只支持+-*/,其他的晢不支持';
break;
}
} else {
return '第1个参数为计算符号,第2、3个参数为需要计算的值,且必须为数字';
}
}
echo calculate('-', 6, 3);
?>
2. Briefly describe advanced MySQL technologies and stories from practice
3. Discuss the uses of symbols like . , – @ & — ++ ^ $ in programming, as detailed as possible
.: String concatenation
,: Separator in an array
-: Subtraction operator
@: Error suppression operator
&: && is a logical operator meaning AND
–: Decrement operator (when placed after a variable, it returns the variable’s value first, then decrements; when placed before a variable, it decrements first, then returns the variable’s value)
++: Increment operator (when placed after a variable, it returns the variable’s value first, then increments; when placed before a variable, it increments first, then returns the variable’s value)
^: XOR operator
$: Variable prefix symbol
4. Discuss your understanding of object-oriented programming
“Object-oriented” decomposes the entities that make up a problem into individual objects. The purpose of establishing an object is not to complete a single step, but to describe the behavior of a certain entity throughout the steps of solving the problem.
6. Write a program to reverse the order of letters in a string
<?php
$v1 = 'abcde';
$v2 = '';
for ($i=strlen($v1)-1; $i>=0; $i--) {
$v2 .= $v1{$i};
}
echo $v2;
?>
7. Write at least 5 methods to optimize a MySQL database
Optimize queries, such as using indexes, replacing subqueries with join queries
Optimize database structure, such as splitting tables, adding intermediate tables, adding redundant fields, analyzing tables, checking tables, optimizing tables
Optimize the speed of inserting records, such as disabling indexes before inserting records, inserting multiple records with a single insert statement
Optimize MySQL server hardware configuration, such as adding memory, increasing the number of disks, improving disk read/write speed
Optimize MySQL server parameter configuration
1. Using JS syntax (not jQuery syntax), write the equivalent statements for the following ($ represents jQuery’s $)
<script>
$.each([0, 1, 2], function(i, n){ alert(i); });
var a = new Array(0, 1, 2);
for (var i = 0; i < a.length; i++) {
alert(i);
}
</script>2. What is the purpose of the following statements? ($ represents jQuery’s $)
2.1
<script>
var a = 2;
var b = 3;
var fun = $.extend({
min:function(a, b){ return a < b ? a : b; },
max:function(a, b){ return a > b ? a : b; }
});
//合并一个对象,{min:2, max:3},一般是需要两个对象才执行合并的
</script>2.2
<script>
$(document).ready(function(){
$("tr").hover(function(){
$(this).addClass("over");
},function(){
$(this).addClass("out");
})
})
//当鼠标移动到tr上时,给tr添加类over,移开时,给tr添加类out
</script>3. What are inline elements? What are block-level elements?
Inline elements:
a – anchor, br – line break, em – emphasis, img – image, input – input box, span – defines an inline block of text, textarea – multi-line text input box, sub – subscript, sup – superscript, label – form label, etc.
Block-level elements:
h1 – heading 1, h2 – heading 2, h3 – heading 3, h4 – heading 4, h5 – heading 5, h6 – heading 6, div – common block-level container, also the main tag for css layout, dl – definition list, dt – item in a definition list, ul – unordered list, ol – ordered list, li – list item, table – table, tbody – table body (main text), td – standard cell in a table, thead – table header, tfoot – table footer (footnote or table note), tr – row in a table, etc.
4. Describe objects in JavaScript based on your understanding
Everything in JavaScript is an object: strings, numbers, arrays, functions…
In addition, JavaScript allows custom objects.
5. List the IE6 hacks you have encountered at work and discuss solutions
Ultimate method: Conditional comments <!–[if lte IE 6]><html><![endif]–>
CSS selector differentiation: IE6 does not support child selectors. First use standard declaration selectors for IE6, then use child selectors to target IE7+ and other browsers
Use !important, which IE6 does not support but other browsers do
When an element is floated, IE6 incorrectly doubles the margin value in the float direction, so try to avoid using float and margin simultaneously
:hover (except for href) is not supported in IE6. It’s best not to use :hover to implement critical functions; use JS events directly instead
For semi-transparent PNG image issues, it is recommended to use png-8 whenever possible. If using png-24 or png-32, you need to implement it via JS
6. What are the ways to include CSS? What is the difference between link and @import?
Using the link tag
Using the style attribute
Using the style tag
Using @import to include
Differences:
link is an XHTML tag, while @import is entirely a method provided by CSS
Difference in loading order: When a page is loaded, the CSS referenced by link is loaded simultaneously, whereas the CSS referenced by @import is loaded only after the entire page has been downloaded
Difference in compatibility: @import is not supported in some older browser versions (IE5-)
Difference when using DOM to control styles: When using JavaScript to control the DOM to change styles, you can only use the link tag, because @import cannot be controlled via the DOM
7. What are the methods for clearing floats, and what scenarios are they suitable for?
Clear floats using an empty tag
Using the overflow property
Clear floats using the after pseudo-element
8. Have you been following HTML5 and CSS3? Briefly describe your understanding of them, or write a few lines of code to explain
HTML5 will become the new standard for HTML, XHTML, and the HTML DOM.
The previous version of HTML was born in 1999. Since then, the web world has undergone massive changes.
HTML5 is still being refined, however, most modern browsers already support certain HTML5 features.
CSS3 is the latest CSS standard.
W3C is still developing the CSS3 specification. Modern browsers have already implemented a considerable number of CSS3 properties.
9. If you were tasked with building a large website with very high traffic, how would you manage all CSS files, JS files, and images?
Establishing front-end development standards, such as coding patterns, CSS reset/global files, aggregating background images, etc.;
Annotating pages, such as marking the start and end of modules;
Annotating basic information like author and module name for individual functional modules;
Unifying the naming conventions for individual functional modules across html/js/css/image files;
Appending status values, like md5 hashes, to the end of front-end file URLs to correspond to a specific version;
Specifying image dimensions and avoiding scaling;
Optimizing images while maintaining a certain quality, such as using ysmush.it (lossless compression);
Compressing and merging files in the production environment;
10. Have you done front-end development for ASP.NET projects? What was your role in the project?
11. There is a website with the following navigation sections:
站长之家|网站运营|设计在线|网络编程|联盟资讯|服务器
Hovering the mouse over 设计在线 displays the following secondary menu:
网页设计|web标准|视频处理|设计活动
Hovering the mouse over 网络编程 also displays the following secondary menu:
php编程|.net编程|xml编程
Moving the mouse away from 设计在线 or 网络编程 will automatically hide the secondary menu
Using JSON or XML data output by the server (construct the data yourself), use JavaScript to output this data into the layer <div id=”nav”></div>. (The method to request server-side data is ajaxRead; the server-side address is: “/ajax.aspx?type=nav”)
function ajaxRead(src,fun){
//This method can read the relevant json or xml data based on the request URL src, and then execute the callback function fun
}
Please construct the JSON or XML data for this menu
<?php
$nav = array(
‘站长之家’ => array(),
‘网站运营’ => array(),
‘设计在线’ => array(
‘网页设计’ => array(),
‘web标准’ => array(),
‘视频处理’ => array(),
‘设计活动’ => array()
),
‘网络编程’ => array(
‘php编程’ => array(),
‘.net编程’ => array(),
‘xml编程’ => array()
),
‘联盟资讯’ => array(),
‘服务器’ => array()
);
print_r($nav);
$code = json_encode($nav);
echo preg_replace(“#\\\u([0-9a-f]+)#ie”, “iconv(‘UCS-2′,’UTF-8’, pack(‘H4’, ‘\\1’))”, $code);
?>
<script>
var json = {“站长之家”:[],”网站运营”:[],”设计在线”:{“网页设计”:[],”web标准”:[],”视频处理”:[],”设计活动”:[]},”网络编程”:{“php编程”:[],”.net编程”:[],”xml编程”:[]},”联盟资讯”:[],”服务器”:[]};
var nav = eval(json);
$(nav).each(function(i,n) {
var val = nav[i];
if (typeof (val.summary) == “object”) {
$(val.summary).each(function(i,n) {
// Secondary menu
});
} else {
// Primary menu
}
});
</script>
Please complete the callback function fun
// Traverse the json data, build a ul menu, and then append it to the div
3. Given a web address, such as the Honghe company homepage: http://www.sc66666.com/index.html, how do you get its content?
<?php
$url = “http://www.sc66666.com/index.html”;
$contents = file_get_contents($url);
echo $contents;
?>
4. Describe the garbage collection algorithms in PHP 5.2 and PHP 5.3 respectively, and compare their pros and cons
PHP 5.2’s garbage collection algorithm – Reference Counting, is intuitive and simple in concept, but prone to causing memory leaks
PHP 5.3’s garbage collection algorithm – Concurrent Cycle Collection in Reference Counted Systems. In scenarios that might trigger cumulative memory leaks, PHP 5.2 experiences continuous cumulative memory leaks, whereas PHP 5.3 can always keep memory leaks below a threshold (related to the root buffer size), but the performance of its garbage collection mechanism is somewhat lower
