Summary of common knowledge points in PHP

Source: Internet
Author: User
PHP Aspects:
The difference between 1,echo print Print_r
ECHO is a PHP statement, print and Print_r is a function, the statement does not return a value, the function can have a return value.
Print prints only the values of a simple type variable.
Print_r can print complex variable values (arrays or objects)
Echo outputs one or more strings.

2,mysql_fetch_array () differs from mysql_fetch_row ()
Mysql_fetch_array () returns an array based on the rows taken from the result set, or False if there are no more rows, with the field name as the index, in addition to the data being indexed as a field.
Mysql_fetch_row () returns a row from the result set as an enumerated array, returning an array of numeric indices starting at 0.
Mysql_fetch_array () is an extended version of Mysql_fetch_row ().

The role of _set () and _construct in object-oriented 3,php
_set () ——-to set the value for the property, _get () Gets the value of the property
_construct ——-can only declare a construction method in a class, only to call the constructor once each time the object is created, not to invoke the method actively, so it is usually used to perform some useful initialization tasks.

The difference between session and Cookie in 4,php
Cookies are information stored on the client and are a mechanism for storing data in a remote browser to track and identify users. PHP sends a cookie in the header of the HTTP protocol, so the Setcookie () function must be called before other information output, similar to the limit of the header () function.
Session is stored on the server side of the information, from this point of view, the session is more secure than the cookie. When the session is created, the server returns the client an encrypted session_id to identify the user, and when the browser shuts down, the session is destroyed so that the value of the session is gone.

5, how to set a cookie and specify a valid time
Bool Setcookie (String name,string value,int expire,string path,string domain,bool secure,bool httponly)
Name:cookie variable Name
Value:cookie Variable Value
Expire: Time of expiry
Path: Valid directory
Domain: Valid domain name, top-level or unique
Secure: If the value is 1, the cookie can only be valid on HTTPS connections, if the default value is 0,http and HTTPS

PHP Settings Cookie
$value = ' something from somewhere ';

Setcookie ("TestCookie", $value); /* Simple cookie settings */
Setcookie ("TestCookie", $value, Time () +3600); /* Valid for 1 hours * *
Setcookie ("TestCookie", $value, Time () +3600, "/~rasmus/", ". example.com", 1); /* Valid directory/~rasmus, valid domain name example.com and all sub-domains */
?>
Use the header () to set the cookie;
Header ("Set-cookie:name= $value [;p ath= $path [;d omain=xxx.com[;]]");
The following parameters are the same as those listed above for the Setcookie function.

Mechanism of the cookie principle:
A) The server sets a cookie (more than one cookie) in the client computer by sending an HTTP Set-cookie header in response.
b) The client automatically sends an HTTP cookie header to the server and the server receives the read.
http/1.x OK
x-powered-by:php/5.2.1
Set-cookie:testcookie=something from somewhere; path=/
Expires:thu, 18:52:00 GMT
Cache-control:no-store, No-cache, Must-revalidate, post-check=0, pre-check=0
Pragma:no-cache
Content-type:text/html

This line implements the cookie function, after receiving this row
Set-cookie:testcookie=something from somewhere; path=/
The browser creates a cookie file on the client's disk and writes it inside:
Testcookie=something from somewhere;
/
This line is the result of our use of Setcookie (' TestCookie ', ' Something from somewhere ', '/'); that is, with the header (' Set-cookie:testcookie=something from somewhere; path=/'); the result.
6,php access control in object-oriented
Public represents the global, and the inner and outer subclasses of the class can access
Private indicates that only this class can be called internally
Protected represents a protected, only class or subclass or parent class that can access

7, what is the function and principle of PHP Mvc,mvc
MVC is a design pattern that makes it mandatory for application input, processing, and output to be separated, using MVC applications as three core parts: models, views, controllers, each dealing with their own tasks.

The principle of MVC: First the controller accepts the user's request and decides which model should be invoked for processing, then the model uses the business logic to process the user's request and return the data, then the controller formats the data returned by the model with the corresponding view and renders it to the user through the presentation layer.
Rationale: The request of the presentation layer (V) is sent to the controller (C), the controller calls the business layer (M) based on the request type, and the final call to the presentation layer is displayed.

The difference between include require in 8,php
These two structures are different from processing failures, include generates a warning, and require causes a fatal error, in other words, if you want to stop processing a page when you encounter a lost file, use require. Include is not the case and the script will continue to execute.
Require use method such as require ("myfile.php"); This table is usually placed at the top of the PHP program, and before PHP is executed, it will be read into the file specified by require to make it part of the PHP program's Web page.
Include using the same method as above, the program is generally placed in the process control of the processing section, the PHP program page is read to the file of the include, only read it in, this way, the program can be executed when the process of simplification.

When the page executes to require (), if require is a PHP, HTML page, then it will immediately go to execute the page. The include, in general, is used to include some inc files. For example, you can use the header and header of your site as an inc file, which is included in each PHP file. Include actually embeds the file you want to include in the current page. and require is going to execute the page you requested right away.
——————————————————————————–
Incluce load when used
Require is loaded at the beginning
The _once suffix indicates that the load is not loaded
The PHP system has a pseudo-compile process when loading PHP programs, which can make the program run faster. But Incluce's documentation is still interpreted to perform
An error occurred in the include file and the main program continues to execute
The Require file went wrong and the main program stopped.
So the included file error has little impact on the system (such as interface files) with include, otherwise with require
The include_once () function, the require_once () function will first check that the contents of the target file have been imported before, and if so, it will not re-import the same content again

10, calculate two time difference 2009.5.12 2009.5.20
$regist 1 = "05/12/2006″;
$regist 2 = "10/05/2007″;
List ($month 1, $day 1, $year 1) = Explode ("/", $regist 1);
List ($month 2, $day 2, $year 2) = Explode ("/", $regist 2);
$regist 1 = mktime (0,0,0, $month 1, $day 1, $year 1);
$regist 2 = mktime (0,0,0, $month 2, $day 2, $year 2);
$time _difference = $regist 2-$regist 1;

11, what are the protocols you know? What do the HTTP protocol error hints mean?
SMTP (Simple Mail Transfer protocal) is referred to as the single message Transfer protocol, and the goal is to provide users with efficient and reliable message transfer.
The full name of the pop is the post Office Protocol, the Post Office Protocol, used for e-mail reception, which uses TCP port 110, which is now commonly used in the third edition, so referred to as POP3
IMAP is an abbreviation for Internet Message Access Protocol, which, as its name implies, primarily provides a protocol for obtaining information over the Internet.
HTTP (hypertexttransferprotocol) is an abbreviation for Hypertext Transfer Protocol, which is used to transmit data of WWW mode, please refer to RFC2616 for details of HTTP protocol.
ie prompts HTTP 403– to disable access
ie prompt HTTP 403.9– forbidden: Too many users are connected
IE prompt HTTP 404– cannot find file
IE prompt HTTP 500– internal server error

  • 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.