Most complete and detailed PHP face questions (with answers)

Source: Internet
Author: User
Tags php template

This article is about the most complete and detailed PHP surface questions (with answers), with a certain reference value, now share to everyone, the need for friends can refer to

1. What does __file__ mean? (5 points)
The full path and file name of the file. If used in the include file, the include filename is returned. Since PHP 4.0.2, __file__ always contains an absolute path, and the previous version sometimes contains a relative path.
2, how to get the IP address of the client? (5 points)

1 $_SERVER[‘REMOTE_ADDR’]

3. Write the statement using the Header function jump page (5 points)

1 Header(‘location:index.php’);

4, $str is a piece of HTML text, using regular expressions to remove all of the JS script (5 points)

12 $pattern= ‘/<script.*>\.+<\/script>/’;Preg_replace($pattern,’’,$str);

5. Write out the statement (5 points) to remove the null value from an array

1 $arr= array(‘’,1,2,3,’’,19);

The first method:

123456 $array1 = array(‘  ‘,1,‘‘,2,3);print_r(array_filter($array1, "del"));function del($var){       return(trim($var)); }

The second method:

123 $arr=array("",1,2,3,"");$ptn="/\S+/i";print_r(preg_grep($ptn,$arr));

6, write out the function to get the current timestamp, and the method of printing the time of the previous day (format: year-month-day time: minutes: seconds) (5 points)

12 Time();Date(“Y-m-d H:i:s”,Strtotime(“-1 day”));

7, write the PHP code conversion function (5 points)

1 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 the individual numbers? (5 points)

1 $arr= explode(“,”,$str);

9, Serialize ()/unserialize () function (5 points)
Serialize () and unserialize () are explained in the PHP manual as:
Serialize-produces a representation of a value that can be stored, the return value is a string that contains a byte stream representing value, does not lose its type and structure, and can be stored anywhere.
unserialize-to create a PHP value from a stored representation
Specific usage:

12 $arr= array(“测试1″,”测试2″,”测试3″);//数组$sarr= serialize($arr);//产生一个可存储的值(用于存储)

Use any method (for example: If you $sarr exist in a text file you can use file_get_contents to obtain) the stored values are saved in $newarr;

1 $unsarr=unserialize($newarr);//从已存储的表示中创建 PHP 的值

10, write a function, the parameter is the year and the month, the output result is the number of days of the specified month (5 points)

123 Function day_count($year,$month){Echodate(“t”,strtotime($year.”-”.$month.”-1”));}

11, the path of a file is/wwwroot/include/page.class.php, write out the method to get the file extension (5 points)

12 $arr = pathinfo ("/wwwroot/ include /page. class .php "); $str = substr ( $arr [' basename ", strrpos ( $arr [' " Code class= "PHP functions" >basename '], '. '));

12. What kind of php template engine have you used? (5 points)
smarty,thinkphp self-brought template engine
13. Simply write a class, instantiate the class, and write out the statements that call the properties and methods of the class (5 points)

12345678910 Class myclass{Public $aaa;Public $bbb;Public function myfun(){Echo “this is my function”;}}$myclass = new myclass();$myclass->$aaa;$myclass->myfun();

14, the local MySQL database db_test has built a table friend, the database connection user is root, password is 123
Friend table field: Id,name,age,gender,phone,email
Please use PHP to connect to MySQL, select all the records from the friend table age > 20 Print results, and count the total number of results of the query. (5 points)

12345678910 <?php$link = Mysql_connect(“localhost”,”root”,”123”) or die(“数据库连接失败!”);Mysql_select_db(“db_test”,$link) or die(“选择数据库失败!”);$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 field UID (int), subject (varchar), score (int)
The UID field of the score table is associated with the ID field of the user table
Requires that the following SQL statements be written out
1) Insert a new record in the user table and insert two records (5 points) associated with the newly added record in the score table
2) Get the user score the score table UID is 2 the highest 5 records (5 points)
3) Total score of users with name "Zhang San" (5 points) using federated queries
4) Delete the user named "John Doe", including the score record (5 points)
5) Empty 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=’张三;4).delete from score where uid in(select id from user where name=’李四’);Delete from user where name=’李四’;5).delete from score;6).drop table user;

 

Http://www.php.cn/php-weizijiaocheng-393700.html

Most complete and detailed PHP face questions (with answers)

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.