PHP classic face question set PHP classic face question set

Source: Internet
Author: User
Tags cas explode php write sorts sql error table definition domain name server least privilege
This article introduces the content of the PHP classic test set PHP Classic test set, has a certain reference value, now share to everyone, have the need for friends can refer to

In combination with my own interview situation these days, facing some of the PHP surface questions listed, basically combined with their own views answered, inappropriate place please point out, and we discuss the analysis, but also hope to help the children are interviewing the shoes:

1. The similarities and differences of Get and post in form submission

Get requests are typically used to fetch data to the server, and post typically submits data to the server side

The parameters of the get transfer are in the URL, there is a limit to the size of the pass parameter, the post has no size limit,

Get is unsafe, post security is higher than get

The GET request is accepted on the server with Request.QueryString, and the POST request is accepted by Requset.form on the server side

what is the base tag for 2.HTML?

Must be written in head, base tag specifies default address or default destination for all links on the page

What
is the difference between 3.echo (), print (), Print_r ()?

ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)
Print () prints only the values of a simple type variable (such as int,string)
Print_r () can print out values for complex type variables (such as arrays, objects)
echo outputs one or more strings

4. Write a regular expression of an
e-mail
/^[a-za-z0-9_-]+@[a-za-z0-9_-]+ (\.[ a-za-z0-9_-]+) +$/
5. Array [' A ', ' B ', ' C '] converted to string ' abc '
echo  implode (', [' A ', ' B ', ' C ']);  echo   Join ([' A ', ' B ', ' C '], ');
6. Get the first occurrence of a string ' AAbB ' in a position
  $str = ' AAbB ';  Echo Strpos ($str, "A");
7. Write a paragraph with a minimum cost implementation to completely reverse the string, e.g. convert "1234567890" to "0987654321". (Write and annotate simple annotations in the language you are most familiar with, do not use functions,
$s = ' 1234567890 '; $o = '; $i = 0;while (Isset ($s [$i]) && $s [$i]! = null) {    $o = $s [$i + +]. $o;} Echo $o;
8. Use recursion to implement a factorial evaluation algorithm F (n): n=5; F (n) =5!=5*4*3*2*1=120
function F ($n) {     if ($n ==0) {          return 1;       } else{          return $n * F ($n-1);}       } Var_dump (F (5));
9. Convert the character length Fang-zhi-gang into the form of a camel Hump method: Fangzhigang
Method one function Fun ($str) {    if (isset ($STR) &&!empty ($str)) {         $newStr = ';         if (Strpos ($str, '-') >0) {             $strArray =explode ('-', $str);              $len =count ($strArray);               for ($i =0; $i < $len; $i + +) {                   $newStr. =ucfirst ($strArray [$i]);}           }                 return $newStr;    }           } Method two function Fun ($str) {   $arr 1=explode (' _ ', $str);    $str = Implode (' ', $arr 1);    Return Ucwords ($STR); } Var_dump (Fun ("Fang-zhi-gang")); Fangzhigang
10. What are the sorting methods built into the array?
Sort ($array); Array Ascending sort rsort ($array); Array descending sort asort ($array);  Sorts the associative array in ascending order according to the value Ksort ($array);  The associative array is sorted in ascending order according to the Arsort ($array);   Sorts the associative array in descending order based on the value Krsort ($array);  Sort associative arrays in descending order according to the key
11. Write code that displays client IP and server IP in PHP
$_server["REMOTE_ADDR"]$_server["SERVER_ADDR"]
12. What is the difference between the statement include and the require? To avoid including the same file multiple times, you can use (?) Statements instead of them?
Require is unconditional inclusion that is, if a process joins require, whether or not the condition will be executed first requireinclude has a return value, and require not (probably because require faster than include) Include file does not exist or syntax error require is fatal error termination execution, include is not
What
is the difference between 13.session and cookie?
Session: Stores the globally unique variables accessed by the user, stored in a PHP-specified directory on the server (SESSION_DIR) in the location of the store cookie: used to store continuous access to a page when used, is stored in the client, For a cookie, it is stored in the user win's temp directory. Both can be set time by time

14.PHP swap the value of two variables without using a third variable

Method One $a.= $b, $b =str_replace ($b, "", $a), $a =str_replace ($b, "", $a);//Method Two list ($b, $a) =array ($a, $b); Var_dump ($a, $b);
15. Write a method to get the file extension
function Get_extension ($file) {   //method one      return  substr (STRRCHR ($file, '. '), 1);      Method two      return  end (Explode ('. ', $file));   } echo  get_extension (' fangzhigang.png ');//png
16. The time format of the day before printing in PHP is 2017-3-22 22:21:21
$a = Date ("y-m-d h:i:s", Strtotime ("-1 Days"));
What security should be considered in 17.SQL statements
(1) Prevent SQL injection, escape special characters, filter or Use precompiled SQL statement binding (2) Use the principle of least privilege, especially do not use root account, micro different action or operation to create different accounts (3) When SQL error occurs, do not expose the database error information to the client
18. Optimizing MySQL Database methods
(1) Select the appropriate field, the typing segment is set to NOT NULL, the database does not compare NULL when querying, (2) Use link (join) instead of subquery, (3) Use Union (Union) query instead of manually create temporary table ; (4) Minimize use of (like) keywords and wildcards (5) Use Transactions and external health
19. What are some of the ways you can address traffic to large-volume websites?
(1) First confirm whether the server hardware satisfies the current traffic, (2) Optimize the database access, (3) prohibit the external hotlinking, (4) control the large file download; (5) use different host shunts; (6) Use traffic analysis statistics;
What is the difference between 20.mysql_fetch_row () and mysql_fetch_array?
Both functions return an array, the difference is that the first function returns an array that contains only the values, we can only $row[0], $row [1], so that the array subscript to read the data, and Mysql_fetch_array () The returned array contains both the first and the form of the key-value pairs , we can read the data in this way (if the database field is USERNAME,PASSWD): $row [' username '] $row [' passwd ']
Several concepts of 21.MySQL: Primary key, foreign key, index, unique index
A primary key (primary key) uniquely identifies a property or group of properties for a row in a table. A table can have only one primary key, but there may be multiple candidate indexes. Primary keys often form referential integrity constraints with foreign keys, preventing data inconsistencies. The primary key guarantees that the record is unique and the primary key domain is not empty, and the database management system automatically generates a unique index for the primary key, so the primary key is also a special index. A foreign key (foreign key) is one or more columns that are used to establish and strengthen links between two table data. FOREIGN key constraints are primarily used to maintain data consistency between two tables. In short, the foreign key of the table is the primary key of the other table, and the foreign key ties the two tables together. In general, to delete a primary key in a table you must first make sure that no other table has the same foreign key (that is, the primary key in the table does not have a foreign key associated with it). Index is used to quickly look for records that have a specific value. Mainly for the convenience of retrieval, is to speed up access, according to certain rules created, generally play the role of sorting. The so-called uniqueness Index, which is basically the same as the previous "normal index", has one difference: all the values of an indexed column can only occur once, that is, they must be unique. Summary: The primary key must be a unique index, and the uniqueness index is not necessarily the primary key. There can be multiple unique indexes in a table, but only one primary key. The primary key column does not allow null values, and the uniqueness index column allows null values. The primary key can be referenced by another field as a foreign key, and the index cannot be referenced as a foreign key.
What are the 22.mysql database engines?
MyISAM, ISAM, HEAP, InnoDB, BDB, CVS ...
23. What do you think of the difference between MyISAM and InnoDB in MySQL engine?
 InnoDB and MyISAM are the two most common table types used by many people when using MySQL, both of which have pros and cons, depending on the application. The basic difference is that the MyISAM type does not support advanced processing such as transaction processing, and InnoDB type support. The MyISAM type of table emphasizes performance, which is performed more quickly than the InnoDB type, but does not provide transactional support, while InnoDB provides transactional support for advanced database functions such as external keys. Here are some of the differences between the details and the implementation: what is the difference between MyISAM and InnoDB? 1. Storage structure MyISAM: Each myisam is stored on disk as three files. The first file name begins with the name of the table, and the extension indicates the file type. frm file stores the table definition. The data file has an extension of. MYD (MYData). The extension of the index file is. MYI (Myindex). InnoDB: All tables are stored in the same data file (possibly multiple files, or stand-alone tablespace files), and the size of the InnoDB table is limited only by the size of the operating system file, typically 2GB. 2, storage space MyISAM: can be compressed, storage space is small. supports three different storage formats: Static table (default, but note that there can be no space at the end of the data, it will be removed), dynamic tables, compressed tables. InnoDB: Requires more memory and storage, it establishes its dedicated buffer pool in main memory for caching data and indexes. 3. Portability, Backup and recovery myisam: data is stored as a file, so it is convenient for cross-platform data transfer. You can operate on a table separately for backup and recovery. InnoDB: The free solution can be copying data files, backing up Binlog, or using mysqldump, which is relatively painful when the amount of data reaches dozens of G. 4. Transaction support MyISAM: The emphasis is on performance, each time the query is atomic, and its execution is much faster than the InnoDB type, but does not provide transactional support. InnoDB: Provides advanced database features such as transaction support transactions, foreign keys, and so on. Transaction Security (Transaction-safe (ACID compliant)) Table with transaction (commit), rollback (rollback), and crash-repair capability (crash recovery capabilities). 5, Auto_incrementmyisam: You can establish a federated index with other fields. The auto-grow column of the engine must be an index, and if it is a composite index, autogrow may not be the first column, and he can be incremented based on the preceding columns. The Innodb:innodb must contain only the index of the field. The auto-grow column of the engine must be an index, and if it is a combined index, it must be the first column of the combined index. 6. Table lockDifferential MyISAM: Only table-level locks are supported, and when the user operates the MyISAM table, the Select,update,delete,insert statement automatically locks the table, and if the locking table satisfies insert concurrency, new data can be inserted at the end of the table. InnoDB: Supports transactional and row-level locks, which are the InnoDB of the most important features. Row locks greatly improve the new performance of multiuser concurrency. But the innodb of a row lock, just where the primary key is valid, where the non-primary key is locked in the full table. 7. Full-text index MyISAM: Supports full-text indexing of fulltext types InnoDB: Full-text indexing of fulltext types is not supported, but InnoDB can use Sphinx plug-ins to support full-text indexing, and it works better. 8. Table PRIMARY KEY MyISAM: Allows tables without any indexes and primary keys to exist, and the index is the address of the save row. InnoDB: If no primary key or non-null unique index is set, a 6-byte primary key is automatically generated (not visible to the user), the data is part of the primary index, and the attached index holds the value of the primary index. 9. The specific number of rows in the table MyISAM: The total number of row tables is saved, if select count (*) from table, the value is taken out directly. InnoDB: The total number of rows in the table is not saved, and if you use SELECT COUNT (*) from table, the entire table is traversed, consuming considerable amounts, but the MyISAM and InnoDB are handled the same way when the wehre condition is added. 10, curd Operation MyISAM: If the implementation of a large number of select,myisam is a better choice. InnoDB: If your data performs a large number of inserts or update, you should use the InnoDB table for performance reasons. Delete is InnoDB better on performance, but when you delete from table, InnoDB does not re-establish the table, but deletes one row at a time, and if you want to empty a table that holds a large amount of data on InnoDB, it is best to use the TRUNCATE TABLE command. 11, FOREIGN key MyISAM: does not support InnoDB: support through the above analysis, can basically consider using InnoDB to replace the MyISAM engine, because InnoDB itself a lot of good features, such as transaction support, stored procedures, views, row-level locking, etc., in the case of a lot of concurrency , I believe InnoDB's performance is certainly much stronger than MyISAM. In addition, any kind of table is not omnipotent, only appropriate for the business type to choose the appropriate table type, to maximize the performance advantage of MySQL. If not very complex web applications, non-critical applications, or can continue to consider MyISAM, theThe body situation can be considered at its own discretion. 

Differences between Redis and Memache cache

Summary one: 1. Data types Redis data types are rich, support for type memcache such as set list supports simple data types, Requires the client to handle complex objects on its own 2. Persistent Redis support data on-ground persistent storage memcache does not support data persistent storage 3. The distributed storage Redis supports Master-slave replication mode memcache can use consistent hash to do the different size of distributed value memcache is a memory cache, the key is less than 250 characters in length, a single item store is less than 1M, and is not suitable for use with virtual machines 4. Data consistency different Redis uses a single-threaded model to ensure that the data is submitted sequentially. Memcache need to use CAS to ensure data consistency. CAS (Check and Set) is a mechanism for ensuring concurrency consistency and belongs to the "optimistic lock" category; The principle is simple: take the version number, the operation, the comparison version number, if the same operation, No operation if inconsistent. 5.cpu using a Redis single-threaded model can only use one CPU, which allows you to open multiple Redis processes summary two: 1.Redis, not all of the data has been stored in memory, which is the biggest difference compared with memcached. 2.Redis not only supports simple k/v types of data, but also provides storage of data structures such as List,set,hash. 3.Redis backup of supporting data, i.e. Master-slave mode data backup. 4.Redis support data persistence, you can keep the in-memory data on the disk, restart the time can be loaded again for use. I personally think that the most essential difference is that Redis has a database feature in many aspects, or a database system, and memcached is simply a simple k/v cache summary three: the difference between Redis and Memecache is: 1, storage mode: Memecache The data are all in memory, the power will hang off, the data can not exceed the memory size Redis has some of the hard disk, this can guarantee the data durability. 2. Data support type: Redis has much more data support than Memecache. 3, using the underlying model is different: The new version of Redis directly built the VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request. 4, the operating environment is different: Redis currently only support Linux to go to the line, thus eliminating the support for other systems, so that can better focus on the system environment optimization, although later Microsoft has a team to write a patch for it. But not on the trunk memcache only as a cache, Cacheredis content can be landed, that is, with MongoDB somewhat similar, and then RediS can also be used as a cache, and can be set Master-slave 

25. There is a B C three column in the table, implemented with the SQL statement: When column A is greater than column B, select column B, or column B when column B is greater than column C, select column C otherwise.

drop TABLE table1  create TABLE table1 (      a int,      b int,      c int  )  insert INTO table1 values (22,24,23)    SELECT * FROM table1    Select (case is A>b then a else B end), (case is b>c then B else C end) from  TA Ble1    Select (case if A>b then a while               a>c then a while               B>c then B else C               end) from  table 1

26. Install Linux system, use Netconfig program to configure the network, what to enter?

Allows users to enter necessary information such as host name, domain name, domain name server, IP address, gateway address, and subnet mask

How does PHP write an interface for someone else to call?

Public Function  Authenticationapi ($data, $url) {         $ch  = Curl_init ();          curl_setopt ($ch, Curlopt_url, $url);           curl_setopt ($ch, Curlopt_post, 1);           curl_setopt ($ch, Curlopt_header, 0);           curl_setopt ($ch, Curlopt_returntransfer, 1);           curl_setopt ($ch, Curlopt_postfields, $data);       The output format can be converted to the JSON format as an array           $tmpInfo = curl_exec ($ch);           Curl_close ($ch);           return $tmpInfo;       }

28. Using the PHP header () function to implement page 404 error prompt function

Header ("http/1.1 404 Not Found");

29.heredoc Structure and usage

echo <<<eot   
30.nowdoc Structure and usage
$str = <<< ' EOD '       Example of string       spanning multiple lines       using Nowdoc syntax. EOD;

31.javascript determine if pop-up windows are masked by program code

var Wroxwin = window.open ("http://www.111cn.net", "_blank"), if (Wroxwin = = null) {    alert ("Oops! The popup window is blocked ");

PHP serialization and deserialization functions

Serialize () serialization of Unserialize () deserialization

33. Use the following table structure to write the SQL statements (members (ID,USERNAME,POSTS,PASS,EMAIL) that have the highest number of posts in the 10 names

Select Memebers.username from members group BY posts DESC limit 10

34,. Install PHP as an Apache module, and in the file http.conf first use the statement (? ) Load the PHP module dynamically and then use the statement (? Allows Apache to treat all files with PHP extensions as PHP scripts.

1.LoadModule php5_module "C:/php/php5apache2.dll") 2. AddType application/x-httpd-php. php

35. What are the transactions in the database?

   A transaction is a series of operations that accomplish a task. As long as one of these operations is unsuccessful, the transaction fails and a rollback event occurs. That is, the previous action is undone, which guarantees consistency of the data. And you can put the operation in the cache temporarily, and so on all operations have successfully committed the database, so that the time-consuming operation is effective operation.
36.apche and Nginx's excellent lack
   Nginx lightweight, more than Apache occupies less memory and resources, anti-concurrency, Nginx processing requests are asynchronous non-blocking, and Apache is blocking type, in high concurrency, nginx can keep low resource consumption and high performance. Apache compared to the advantages of Nginx: Rewrite than Nginx rewrite powerful, less bug, stable. (Need performance with nginx, for stability on Apache).
37. Ask for the difference of two dates, for example, 2007-2-5 ~ 2007-3-6 Date Differential
Method One: Use the datetime class $day1 = ' 2003-09-16 '; $day 2 = ' 2011-11-23 '; $d 1 = new DateTime ($day 1); $d 2 = new DateTime ($day 2); Echo $d 1-&G T;diff ($d 2)->days;//method Two, using a timestamp to calculate echo (Strtotime ($day 2)-Strtotime ($day 1))/(24*3600);
38. What does the following code do for you? Please explain. $date = ' 08/26/2003 ';p rint ereg_replace ("([0-9]+)/([0-9]+]/([0-9]+)", "\\2/\\1/\\3", $date);
     This is the conversion of a date from MM/DD/YYYY format to dd/mm/yyyy format. A good friend of mine told me that this normal expression can be disassembled into the following statement, for such a simple representation is not necessary to disassemble, purely for the convenience of interpretation://corresponds to one or more 0-9, followed by a diagonal number $regexpression = "([0-9]+)/";/ Should be one or more 0-9, followed by another oblique number $regexpression. = "([0-9]+)/";//corresponds to one or more 0-9$regexpression. = "([0-9]+)"; As for \\2/\\1/\\3 is used to correspond to parentheses, The first pair of parentheses is the month

39. In PHP, the name of the current script (not including the path and query string) is recorded in the predefined variable (?), while the URL linked to the current page is recorded in the predefined variable (?).

(1) Echo $_server[' php_self ']; (2) Echo $_server["Http_referer"];

40. The argument of a function cannot be a reference to a variable unless the (?) is set to on in PHP.ini.

Allow_call_time_pass_reference

Let's write it down here today! In the late interview encountered different face questions, I am editing here, I hope this article will bring you help, feel write good, for you to help in the please move your hand to pay attention to me and the likes to share, I wish you are looking for a job, you can find a satisfactory job. Wish you a new trip!

Related Article

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.