PHP Side question php section (i)

Source: Internet
Author: User

1. What is the difference between double quotation marks and single quotation marks?

    • Double quote explanatory variable, single quote not explanatory variable;

    • Enclose single quotation marks in double quotes, in which the variable is interpreted if there is a variable in the single quotation mark;

    • Double quotes explain escape characters, single quotes do not interpret escape characters, but explain ' \ and \ \;

    • the efficiency of single quotation marks is higher than double quotation marks (because the double quotation marks should be traversed first, to determine if there are no variables, and then to operate, and single quotation marks do not need to judge);

    • The variable name of double quotes must be followed by a special character that is not a number, a letter, an underscore, or enclosed in a variable name, otherwise it will be a whole, resulting in a syntax error.

2. What is the difference between post, GET, PUT, and Delete methods in HTTP? (1) Differences in how get and post are submitted in the form
    • Get is the URL where the parameter data queue is added to the Action property of the submission form, and the value corresponds to the field one by one in the form, which is visible from the URL; Post is through the httppost mechanism, The user cannot see the process by passing each field in the form with its contents in the head of the HTML to the URL address referred to by the Action property
    • For Get mode, the server side uses Request.QueryString to get the value of the variable, and for post, the server uses Request.Form to get the submitted data.
    • The amount of data sent by the get is small (restricted by the browser, different browser limit length is not the same), the post transmits a large amount of data, generally is not limited by default, but theoretically, the maximum IIS4 in 80KB,IIS5 is 1000k,get security is very low, post security is high
(2) The difference between post, get, put, delete mode
    • A GET request sends a request for data to the database to obtain information, which, like a database's select operation, simply queries the data, does not modify, add data, and does not affect the contents of the resource, that is, the request does not have side effects. The results are the same no matter how many times you do it.

    • A put request is a change of information by sending data to the server, which, like the update operation of a database, modifies the contents of the data, but does not increase the type of data, that is, the result is not different regardless of how many times the put operation is made.

    • A POST request, like a put request, sends data to the server, but the request alters resources such as the type of data, and creates new content just like the insert operation for a database. Almost all of the current commit operations are requested by post.

    • The delete request, as its name implies, is used to delete a resource, which is like a database delete operation.

(3) The difference between get and post
    • The parameters of the get commit are visible in the URL and are less secure than post.

    • The number of Get transfers is small (restricted by the browser, not the maximum length of the browser), the post value can be set in php.ini;

    • Get is generally used to obtain data from the server, post is generally used to submit data to the server;

    • Get execution efficiency is higher than post.

3. The difference between Echo, Print_r (), Print, Var_dump ()

(1) Echo and print differences

    • Echo, print is the structure language, echo (), print () is a function;

    • echo outputs more than one string (separated by commas), and print can only output a single string;

    • ECHO has no return value, print has a return value;

    • echo efficiency is higher than print.

(2) difference between echo, print, Print_r (), Var_dump ()

    • ECHO language structure, output one or more strings, separated by commas, with no return value and cannot be used as part of an expression;
    • Print is also a keyword in PHP, with a return value that prints only the value of a simple type variable (such as int,string) and returns True if the string display succeeds, otherwise false;
    • Print_r () can print out the value of a complex type variable (such as an array, an object) as a list, beginning with an array, an object, but Print_r output a boolean and null results without meaning, because all is printed "\ n", so Var_dump () The function is more suitable for debugging;
    • Var_dump () determines the type and length of a variable and outputs the value of the variable.
What is the difference between statement include and require? To avoid including the same file multiple times, you can use the (?) Statements instead of them
    • Require is an unconditional inclusion, that is, if a process joins require, whether or not the condition will be executed first require, when the file does not exist or cannot be opened, will prompt the error, and will terminate the program execution

    • Include has a return value, and require does not (possibly because this require faster than include), if the contained file does not exist, then will prompt an error, but the program will continue to execute

    • Require is fatal when the include file does not exist or is syntactically incorrect, and include is not

    • Require_once, include_once, contains only one time, avoids repeating the inclusion
4, talk about the understanding of MVC

Applications that are completed by models, views, and controllers are emitted by the model to implement functions to the Controller, the Controller receives the organization functions passed to the view

Pros: ① can implement code reuse, avoid generating code redundancy, and implement code separation between ②m and V, so that the same program can use different representations

5. HTTP status Code

Common HTTP Status codes:

    • 200-Successful request
    • 203-Non-authorized information. The request was successful. But the meta information returned is not on the original server, but a copy
    • 204-no content. The server processed successfully, but the content was not returned. Make sure the browser continues to display the current document without updating the page
    • 205-Reset the content. The server processing succeeds, and the user terminal (for example: browser) should reset the document view. The browser's form fields can be cleared by this return code
    • 206-Partial content. The server successfully processed a partial GET request
    • 301-permanently move. The requested resource has been permanently moved to the new URI, the return information will include the new URI, and the browser will automatically redirect to the new URI. Any future new requests should be replaced with a new URI
    • 302-Temporary movement. Similar to 301. But resources are only temporarily moved. The client should continue to use the original URI
    • 305-Use a proxy. The requested resource must be accessed through the proxy
    • 401-Request for user authentication
    • 403-The server understands the request of the requesting client, but refuses to execute the request
    • 404-The requested resource (Web page, etc.) does not exist
    • 503-The server is temporarily unable to process client requests due to overloading or system maintenance. The length of the delay can be included in the server's Retry-after header information
    • 505-The server does not support the version of the requested HTTP protocol and cannot complete processing

HTTP Status Code classification:

    • 1**-Information, requests received by the server that require the requestor to continue to perform the operation
    • 2**-Successful, the operation is successfully received and processed
    • 3**-redirect, requires further action to complete the request
    • 4**-Client error, request contains syntax error or unable to complete request
    • 5**-Server error, the server has an error while processing the request
6, commonly used super-global variables (8)
    • $_get----->get Transfer Mode
    • $_post----->post Transfer Mode
    • $_request-----> can receive values for get and post two ways
    • $_file-----> Upload files using
    • $GLOBALS-----> All the variables are in there.
    • $_server-----> System Environment variables
    • $_session-----> Session control will be used.
    • $_cookie-----> Session control will be used.

————————————————————————————————————————————————————————————————————————————————

    • $_env------->php To resolve information about your server environment

7, PHP5 Magic Variable and magic method?

(1) Magic method

1, __construct () : called automatically when instantiating an object.

2. __destruct () : automatically called at the end of destroying the object or script execution.

3, __call () : Executes this function when the calling object does not exist.

4, __get () : Executes this function when getting an object that does not exist.

5. __set () : Executes this function when setting a property that does not exist for an object.

6. __isset (): executes this function when detecting whether a property of an object exists.

7. __unset () : Executes this function when destroying a property of an object.

8. __tostring () : Executes this function when the object is output as a string.

9. __clone () : Executes this function when cloning an object.

10. __autoload () : When instantiating an object, execute this function to automatically load the class when the class does not exist.

11, __sleep () :Serialize was called before, you can specify the object properties to serialize.

12, __wakeup :unserialize was called before, you can perform the initialization of the object work.

13, __set_state () : called when Var_export is called . Use The return value of __set_state as the return value of Var_export.

14. __invoke () : Executes this method when the object is used as a function, which is generally not recommended.

(2) Magic constant

1. __line__: The current line number in the file.

2, __file__: The full path and file name of the file.

3. __dir__: The directory where the files are located.

4, __function__: function name (PHP 4.3.0 new addition). Since PHP5 this constant returns the name (case-sensitive) when the function is defined.

5, __class__: The name of the class (PHP 4.3.0 new Plus). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive).

6. __namespace__: The name of the current namespace (case sensitive). This constant is defined at compile time (PHP 5.3.0 is new).

7, __trait__: Trait's name (PHP 5.4.0 new). From PHP 5.4 This constant returns the name of the trait when it is defined (case-sensitive). The Trait name includes its declared function area (for example, Foo\bar).

8, __method__: The method Name of the class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive).

8, how to obtain the client's IP (requires an int) and the server IP code

Client: $_SERVER["REMOTE_ADDR"];或者getenv(‘REMOTE_ADDR‘) ip2long进行转换

Server-side: $_SERVER["SERVER_ADDR"]; orgethostbyname(‘www.baidu.com‘)

9, <?php Echo Count (strlen ("http://php.net"));? Results of > execution

Output 1

Explanation: Count (Var) is used to count the number of elements in an array or object. When var is null or an empty array, the result is 0. If var is a normal variable, 1 is returned . Returns the number of elements or attributes in Var under normal conditions.

10. What do I need to pay attention to using the list () function?

List () is a syntactic structure. The list ($array) is used to quickly assign elements in an array to variables. When used, be aware that$array must be an indexed array, and the index value starts at 0 .

Usage:

$arr = Array (' 23 ', ' 1 ', ' 30 ', ' 12 ', ' 5 ');
List ($a,, $b) = $arr;
echo ' $a: '. $a. '; $b: '. $b;

Output: $a: $b: 30

11, explain the difference between the value and the reference in PHP, and explain when to pass the reference?

    Value
    is to assign the value of the argument to the row parameter
    modify the row parameter, The value of the argument is not affected

    address
    is a special way to pass a value, except that he passes an address, not an ordinary one, such as int
    after the address is passed, the argument and the row parameter points to the same object

    references
     True address-pass parameter
    is passed, the row arguments and arguments are all the same object, but their names are different.
    Modification of a row parameter affects the value of an argument

$a = "123";
$b = & $a;//reference Assignment (add & symbol before source variable)
echo $a. " -". $b; Output: 123-123
echo "<br/>";
$b = "456465"; Output: 456465-456465
echo $a. " -". $b;

Conclusion:
The arguments change when the parameter sounds change when PHP is referenced;

The value is passed only to the target object, which is equivalent to copy; The system will re-open an identical memory space for the target object.
The reference is to pass the object's in-memory address to the target object, which is equivalent to having the target object and the original object correspond to the same memory storage space . In this case, the data in memory will change if the target object is modified.

The object by default is a reference to a large data, the reference is better, which can save memory overhead

12, how to run the PHP script under the command (two ways), how to pass parameters to the PHP script?

(1) Running PHP script

Method One: first enter the PHP installation directory, execute PHP path / file name .

Example: Php my_script.php php-f "my_script.php"

Method two: Php-r "php script";( do not need to add php start character and Terminator ).

Example: Php-r "Print_r (Get_defined_constants ());

(2) passing parameters to the PHP script:

Method One: Receive with $ARGV or $ARGC parameter

PHP Script:

<?php
echo "received {$ARGC} parameters";
Print_r ($ARGV);

Perform:

[Email protected] lee]#/usr/local/php/bin/php test.php
1 Parameters received Array
(
[0] = test.php
)
[Email protected] lee]#/usr/local/php/bin/php test.php a b c D
5 Parameters received Array
(
[0] = test.php
[1] = a
[2] = b
[3] = C
[4] = d
)

Method Two : Use the getopt function

PHP Script:

<?php
$param _arr = getopt (' a:b: ');
Print_r ($param _arr);

Perform:

[Email protected] lee]#/usr/local/php/bin/php test.php-a 345
Array
(
[A] = 345
)
[Email protected] lee]#/usr/local/php/bin/php test.php-a 345-b 12q3
Array
(
[A] = 345
[B] = 12q3
)
[Email protected] lee]#/usr/local/php/bin/php test.php-a 345-b 12q3-e 3322ff
Array
(
[A] = 345
[B] = 12q3
)

What is Magic Quotes

Waring: This feature has been deprecated since PHP 5.3.0 and will be removed from PHP 5.4.0.

Magic Quotes are a process that automatically escapes data into a PHP script, preferably not escaped while encoding and escaped as needed at run time

When turned on, all '(single quotes),"(double quotes),\(backslash), and NULL characters are automatically added with a backslash to escape. This is exactly the same as the addslashes () function.

A total of three magic quote instructions:

    • MAGIC_QUOTES_GPC impact HTTP Request data (Get,post and cookies). Cannot be changed at run time. The default value in PHP is on . see GET_MAGIC_QUOTES_GPC ().
    • Magic_quotes_runtime If open, most of the functions that get data from external sources and return the data, including from the database and text files, are escaped by backslashes. This option can be changed at run time, the default value in PHP is off . see set_magic_quotes_runtime () and get_magic_ Quotes_runtime ().
    • Magic_quotes_sybase ' . Double quotes, backslashes, and NULL characters are not escaped. ini_get ().

PHP Side question php section (i)

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.