These 15 PHP interview questions can be done, and you can basically find a job

Time:2022-5-5

1、FILEWhat do you mean? (5 points)
The full path and file name of the file. If used in an include file, the include file name is returned. Since PHP 4.0.2,FILEAlways include an absolute path, while previous versions sometimes included a relative path.

2. How to get the IP address of the client? (5 points)

$_SERVER[‘REMOTE_ADDR’]

3. Write a statement that uses the header function to jump to the page (5 points)
Header(‘location:index.php’);

4. $STR is an HTML text. Use regular expressions to remove all JS scripts in it (5 points)
$pattern = ‘/<script.*>.+</script>/’;
Preg_replace($pattern,’’,$str);

5. Write out the statement to remove the null value in an array (5 points)
$arr = array(‘’,1,2,3,’’,19);

The first method:
$array1 = array(‘ ‘,1,’’,2,3);
print_r(array_filter($array1, “del”));
function del($var)
{
return(trim($var));
}

The second method:
$arr=array(“”,1,2,3,””);
$ptn=”/\S+/i”;
print_r(preg_grep($ptn,$arr));

6. Write out the function to obtain the current timestamp and the method to print the time of the previous day (Format: year month day hour: minute: Second) (5 minutes)
Time();
Date(“Y-m-d HThese 15 PHP interview questions can be done, and you can basically find a jobs”,Strtotime(“-1 day”));

7. Write the function of PHP for code conversion (5 points)
Iconv(‘utf-8’,’gb2312’,$str);

8. $STR = “1,3,5,7,9,10,20”, what function can be used to convert the string STR into an array containing various numbers? (5 points)
$arr = explode(“,”,$str);

9. Function of serialize() / unserialize() function (5 points)
The explanations of serialize() and unserialize() in the PHP manual are:
Serialize – generate a representation of a storable value, and the return value is a string. This string contains the byte stream representing value, without losing its type and structure, and can be stored anywhere.
Unserialize – creates a PHP value from the stored representation
Specific usage:
$arr = array (“test 1 ″,” test 2 ″, “test 3 ″)// array
$sarr = serialize($arr);// Generate a storable value (for storage)

//Use any method (for example, if you store $Sarr in a text file, you can get it with file_get_contents) to get the stored value and save it in $newarr;
$unsarr=unserialize($newarr);// Create PHP values from stored representations

10. Write out a function, the parameters are year and month, and the output result is the number of days of the specified month (5 points)
Function day_count($year,$month){
Echo date(“t”,strtotime($year.”-”.$month.”-1”));
}

11. The path of a file is / wwwroot / include / page class. PHP, write out the method to obtain the file extension (5 points)
$arr = pathinfo(“/wwwroot/include/page.class.php”);
$str = substr($arr[‘basename’],strrpos($arr[‘basename’],’.’));

12. What kind of PHP template engine have you used? (5 points)
Smarty, ThinkPHP’s own template engine

13. Please simply write a class, instantiate the class, and write the statement calling the properties and methods of the class (5 points)
Class myclass{

Public $aaa;
Public $bbb;
Public function myfun(){
Echo “this is my function”;
}

}

$myclass = new myclass();
$myclass->$aaa;
$myclass->myfun();

14. Local MySQL database db_ The table friend has been built in test. The connection user of the database is root and the password is 123
The fields in the friend table are: ID, name, age, gender, phone, email
Please use PHP to connect to MySQL, select all records with age > 20 in the friend table, print the results, and count the total number of query results. (5 points)
<?php
$link = Mysql_ Connect (“localhost”, “root”, “123”) or die (“database connection failed!”);
Mysql_ select_ DB (“db_test”, $link) or die (“failed to select database!”);
$sql = “select id,name,age,gender,phone,email from friend where age>20”;
$result = mysql_query($sql);
$count = mysql_num_rows($result);
While($row = mysql_fetch_assoc($result)){
Echo $row[‘id’];
}

15. There are two tables below
User table field ID (int), name (varchar)
Score table fields uid (int), subject (varchar), score (int)
The uid field of the score table is associated with the ID field of the user table
The following SQL statements are required
1) Insert a new record in the user table and two records associated with the newly added record in the score table (5 points)
2) Obtain the top 5 records of users with uid of 2 in the score table (5 points)
3) Use the joint query to obtain the total score (5 points) of the user whose name is “Zhang San”
4) Delete the user whose name is “Li Si”, including the score record (5 points)
5) Empty the score table (5 points)
6) Delete user table (5 points)
1). mysql_query(“insert into user(name) values(‘test’)”);
$id = mysql_insert_id();
Mysql_query(“insert into score(uid,subjext,score) values(“.$id.”,’english’,’99’)”);

2).$sql = select uid,sunjext,score from score where uid=2 order by score desc limit 0,5;

3). Select s.score from score s right join user u on u.id = s.uid where u.name = ‘Zhang San;

4). Delete from score where uid in (select id from user where name = ‘Li Si’);

Delete from user where name = ‘Li Si’;

5).delete from score;

6).drop table user;

This work adoptsCC agreement, reprint must indicate the author and the link to this article

There are great scholars in conversation and laughter, and there are no white men in communication!