Some basic knowledge about PHP

Source: Internet
Author: User
Tags echo date get ip

The meaning of several status codes in the 1.HTTP protocol: 503 500 401 403 404 200 301 302.

Answer:

503 (service Unavailable) The server is not currently available (due to overloading or downtime maintenance). typically, This is only a temporary state.

500 (server Internal Error) the server encountered an error and could not complete the Request.

401 (unauthorized) Request Authentication is Required. The server may return this response for pages that need to log On.

403 (forbidden) the server rejects the Request.

404 (not Found) The requested Web page was not found by the Server.

200 (success) The server has successfully processed the Request. typically, This indicates that the server provided the requested Web Page.

301 (permanently Moved) The requested page has been permanently moved to a new Location. When the server returns this response (a response to a GET or HEAD request), the requestor is automatically forwarded to the new Location.

302 (temporary Move) The server is currently responding to requests from a Web page in a different location, but the requestor should continue to use the original location for future Requests.

2.include require include_once require_once the Difference.

There are two ways to refer to a file: require and include.

Require use methods such as require ("file.php");. This function is usually placed at the front of the PHP program, and before the PHP program executes, It is read into the file specified by require to make it a part of the PHP Program's Web page. Commonly used functions, You can also use this method to introduce it into the web Page.

Include usage methods such as include ("file.php");. This function is usually placed in the processing part of the process Control. The PHP Program page reads the include file before it is read in. This way, you can simplify the process when the program Executes.

The _once suffix indicates that the load is not loaded

3. Please write the meaning of the data type (int char varchar datetime text), What is the difference between varchar and char.

Int: integer type, 4 byte size, range (-2 147 483 648,2 147 483 647)

Char: string type, size 0-255 bytes

Varchar: string type, size 0-65535 bytes

Datetime: A date and time type that represents a time value, 8 bytes in size, format: yyyy-mm-dd HH:MM:SS

Text: string type, 0-65535 bytes, for long text data storage

The difference between Char and varchar:

Char (13) fixed length, such as ' www.nynds.com ' storage requires space of 13 characters

VARCHAR (13) variable length as ' www.nynds.com ' requires storage space of 14 characters

As you can see from the above, the char length is fixed, no matter how much data you store, he will be fixed length.

The varchar is variable in length but he adds 1 characters to the total length, which is used to store the Location. So the user can do it according to their own data type in actual Application.

For some reason Char has a fixed length, so the processing speed is much faster than varchar.

The difference between the 4.Mysql storage engine MyISAM and Innodb.

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 advanced database functionality such as transactional support and external keys.

5. The time format for printing the previous day in PHP is 2006-5-10 22:21:21

echo Date ("y-m-d h:i:s", time () -3600*24);

6.echo (), Print (), print_r () differences

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 only prints out values for simple type variables (such as Int,string)

Print_r can print out values for complex type variables (such as arrays, objects)

7. How to implement string flipping

(1) English string inversion

$str = ' abc,def. '; Always remember to recommend using single quotes ", high efficiency

$newstr = Strrev ($str);

Echo ' original string is: '. $str; ' Abc,def. '

Echo ' flipped string is: '. $newstr; '. FED,CBA '

Echo ' <br/> ';

But when there is Chinese presence, there is garbled

$str = ' A This b is the c-sub, the d-string ef. ';

$newstr = Strrev ($str);

Echo ' original string is: '. $str; ' A This B is the c-sub, the d-string ef. '

Echo ' flipped string is: '. $newstr; Output a string of garbled characters

Echo ' <br/> ';

(2). string reversal in Chinese and English

echo "<meta charset = ' Utf-8 ' >";

function Mystrrev ($str, $encoding = ' Utf-8 ') {

$newstr = ";

$len = Mb_strlen ($str);

For ($i = $len-1; $i >=0; $i-) {

$newstr. = mb_substr ($str, $i, 1, $encoding);

}

Return $newstr;

}

$string = ' believe that women is right. ‘;

Echo $string;

Echo ' <br/> ';

Echo Mystrrev ($string); Of Indeed it is nemow.

8. The method of realizing Chinese string interception without garbled characters

$start: specifies the position at which to start intercepting the string, $length specifies the length of the Intercept character

function Substr2 ($string, $start, $length)

{

$len = strlen ($string);

If ($len > $length)

{

$str = ";

$len 1 = $start + $length; The location where the original string was intercepted

For ($i = $start; $i < $len 1; $i + +)

{

If (ord (substr ($string, $i, 2)) > 0xa0)//in ascii, 0xa0 denotes the beginning of the kanji

{

$str. =substr ($string, $i, 2);

$i + +;

}

Else

{

$str. =substr ($string, $i, 1);

}

}

Return $str. ' ... ';

}

Else

{

Return $string;

}

}

9. How do I get the content of a Web page address using Php's environment variables? How do I get an IP address?

"http://". $_server [' http_host '].$_server[' php_self '];//get web address

$_server[' remote_addr '//get IP Address

10. Find the difference of two dates, such as the date difference of 2017-2-5~2017-3-6

$day = (strtotime (' 2017-2-5 ')-strtotime (' 2017-3-6 '))/8600;

Some basic knowledge about PHP

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.