PHP Interview Questions (Basic)

 Watson Blog October 16, 2017 13:11:15 Web hodgepodge comment one hundred and eighty-three Reading mode

1. What are the functions of strlen() and mb_strlen() respectively?

Both strlen() and mb_strlen() are used to obtain the length of a string. strlen() is only for single byte encoded characters, that is, to calculate the total number of bytes of a string. If it is multi byte encoding, such as gbk and utf8, strlen() is used to obtain not the total number of characters but the total number of bytes. You can use mb_strlen to obtain the number of characters. Pay attention to two points when using mb_string, One is to enable the mbstring extension, but to specify the character set.

 PHP Interview Questions (Basic)

Use the following example

 PHP Interview Questions (Basic)

? 2. Both include and require can include a file into the current file. What's the difference between them? What is the difference between include and include_once?

The include function will read the specified file and execute the program inside;

The require function will read in the contents of the object file and replace itself with these contents;

In addition to the different ways of handling imported files, the biggest difference between include and require is that include generates a warning when importing files that do not exist and the script will continue to execute, while require will cause a fatal error and the script will stop executing. In addition to the different ways of handling imported files, the biggest difference between include and require is that include generates a warning when importing files that do not exist and the script will continue to execute, while require will cause a fatal error and the script will stop executing.

The include_once (require_once) statement includes and runs the specified file during script execution. This behavior is similar to the include (require) statement, except that if the code in the file has been included, it will not be included again, but only once. Include_once (require_once) needs to query the list of loaded files, confirm whether they exist, and then load them again. The include_once statement includes and runs the specified file during script execution. This behavior is similar to the include statement. The only difference is that if the file has been included, it will not be included again. As the name of this statement implies, it can only be included once;

3. What is the difference between POST and GET?

1. GET is to obtain data from the server, POST is to transfer data to the server.

2. GET is received by sending HTTP protocol through URL parameter transmission, while POST is entity data submitted through form

3. The amount of data transmitted by GET is small and cannot be greater than 2KB. The amount of data transmitted by POST is large, and it is generally defaulted to unlimited. But in theory, The maximum size in IIS4 is 80KB, 100KB in IIS5.

4. GET security is very low, POST security is high.

4. What is the difference between foo() and @ foo()?

Foo() will execute this function, and any interpretation error, syntax error, and execution error will be displayed on the page.

@Foo () will hide the above error information when executing this function.

Many applications will use @ mysql_connect() and @ mysql_query to hide the error information of mysql. This is not good. Errors should not be hidden and should be properly handled.

5. Information about the current script, $_SERVER, in PHP.

Client IP: $_SERVER ["REMOTE_ADDR"]

Server IP: $_SERVER ["SERVER_ADDR"]

Get the execution path of the current script: $_SERVER ["SCRIPT_FILENAME"] or __FILE__

Name of the current script: $_SERVER ["PHP_SELF"] or $_SERVER ["SERIPT_NAME"]

URL address to link to the previous page: $_SERVER ["HTTP_REFERER"]

6.sort(), asort(), ksort(), arsort(), What are the differences between rsort ().

Sort() sorts the array. When the function ends, the array elements will be rearranged from lowest to highest.

Rsort () sorts the array in reverse order.

Asort () sorts arrays and maintains index relationships.

Arsort () reverse sorts the array and maintains the index relationship.

Ksort () sorts arrays by key name and reserves the association between key name and data, which is mainly used to associate arrays.

7. What are variable variables? What is the input value of the following program?

Get the value of a common variable as the variable name of this variable.

 PHP Interview Questions (Basic)

The above program output: hotdog

8. How to define constants and check whether a constant is defined?

Define constant: define()

Check whether the constant is defined: defined (), for example

 define("TEST","hello world"); if(defined("TEST")){ echo TEST; }

9. Execute program segment<? php ?echo 8%(-2) ?>, The output is:

%For modular operation, the above program will output 0

$a% $b, whose positive and negative results depend on the sign of $a.

echo ((-8)%3); ? ? // Output - 2

echo (8%(-3)); ? ? ?// Output 2

10. What will echo count ("abc") output ;

The count() function calculates the number of cells in an array or the number of attributes in an object, usually an array(). For an object, if SPL is installed, you can implement the Countable Interface to call count(). This interface has only one method, count(), which returns the return value of the count() function.

If the parameter is not an array or an object that implements the countable interface, 1 will be returned, with one exception. If the parameter is NULL, the result is 0.

11. What is the difference between single quotation marks and double quotation marks in PHP? Which is faster?

Single quotation marks are faster

Data in single quotation marks will not be parsed (any variable and special escape character), so it is faster. Data in double quotation marks will be parsed. For example, variable ($var) values will be substituted into strings, and special escape characters will also be parsed into specific single words.

Single quotation marks, for example:

 $name='hello'; echo 'the $name';

Will output? the $name

If it is a double quotation mark

 $name='hello' echo "the $name"

The hello will be output

12. Briefly describe GBK, GBK2312,BIG5,GB18030

GB2312 supports fewer Chinese characters, GBK is more abundant than GB2312 in Chinese characters, including all Chinese, Japanese and Korean characters, Compared with GBK, GB18030 has added some ethnic Chinese character databases, which are more diversified and rarely used by ordinary people. Generally, simplified Chinese uses GBK while traditional Chinese uses BIG5

13. Briefly describe the usage of empty () function

bool empty($var) ? If var Is a non null or non-zero value, then empty() return FALSE let me put it another way, "" zero "0" NULL FALSE array() var $var; And objects without any attributes will be considered null, if var If it is empty, return TRUE

14. Usage of is_null() function?

Detect whether the variable is NULL. If it is null, return TRUE, otherwise return FALSE. Generally, there are three cases when a variable is recognized as NULL: 1. It is assigned as NULL; 2. It has not been assigned; 3. It is unset().

15. What is the difference between an interface and an abstract class?

Abstract classes are classes that cannot be instantiated and can only be used as parent classes of other classes. Abstract classes are declared through the keyword abstract.

Similar to ordinary classes, abstract classes contain member variables and member methods. The difference between the two is that abstract classes contain at least one abstract method.

An abstract method has no method body. It is born to be overridden by subclasses.

The format of abstract method is: abstr function abstractMethod()

The interface is declared through the interface keyword. The member constants and methods in the interface are public, and the method can not write the keyword public.

The methods in the interface also have no method body, and the methods in the interface are also inherently implemented by subclasses.

The functions of abstract classes and interface implementations are very similar. The biggest difference is that interfaces can implement multiple inheritance. The selection of abstract classes or interfaces in applications depends on the specific implementation.

The subclass inherits the abstract class and uses extends, and the subclass implementation interface uses implements.

Organized from: http://www.cnblogs.com/coderchuanyu/p/3993820.html

 Watson Blog
  • This article is written by Published on October 16, 2017 13:11:15
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/696.html

Comment