PHP Learning Notes

Source: Internet
Author: User
Tags change settings echo date http post mysql query setcookie unique id xml parser

1.VC9 is specifically designed for IIS, and VC6 is provided for other Web services software, such as Apache.

Php.ini-developmen and Php.ini-production appear in the new version of 2.PHP5
These files have a new name:
Php.ini-production corresponds to php.ini-recommended
Php.ini-development corresponds to Php.ini-dist
To install PHP under Windows, you will typically rename php.ini-dist or php.ini-recommended to php.ini.
According to the instructions, the difference is that php.ini-dist is suitable for the development of program use (test),
While Php.ini-recommended has a high security setting, it is suitable for on-line product use.

3. Thunderbolt will occupy 80 ports

4.phpinfo () for system functions, output PHP environment information

5.PHP is a loosely-typed language (loosely Typed Language)
In PHP, you do not need to declare a variable before you set it.
Depending on how the variable is set, PHP automatically converts the variable to the correct data type.

6. In PHP, there is only one string operator.
The collocated operator. Used to connect two string values together.
such as: Echo $txt 1. ” ” . $txt 2;
To separate the two variables, we inserted a space between $txt 1 and $txt 2.

The 7.strlen () function is used to calculate the length of a string.
such as: Echo strlen ("Hello world!");

The 8.strpos () function is used to retrieve a string or a character within a string.
If a match is found in the string, the function returns the first matching position. If no match is found, FALSE is returned.
such as: Echo Strpos ("Hello world!", "World");
Note: The first index position in the string starts at 0 instead of 1.

The 9.array () function is used to create a new array.

10. Array of values:
$names = Array ("AAA", "BBB", "CCC");
Equivalent to:
$names [0] = "AAA";
$names [1] = "BBB";
$names [2] = "CCC";

11. Associative Arrays:
$ages = Array ("AAA" =>42, "BBB" =>60, "CCC" =>34);
Equivalent to:
$ages [' AAA '] = "42″;
$ages [' BBB '] = "60″;
$ages [' CCC '] = "34″;

12. Multidimensional Arrays:
$families = array
(
"Griffin" =>array
(
"Peter",
"Lois",
"Megan"
),
"Quagmire" =>array
(
"Glenn"
),
"Brown" =>array
(
"Cleveland",
"Loretta",
"Junior"
)
);

13.foreach usage:
$arr =array ("One", "one", "one", "three");
foreach ($arr as $value)
{
echo "Value:". $value. "<br/>";
}

14. NewLine:<br/>

15. Form Validation:
User input should be validated whenever possible. The client authenticates faster and reduces the load on the server.
However, any traffic is so high that you have to worry about the server resources of the site, it is necessary to worry about the security of the site. If the form accesses a database, it is very necessary to take server-side validation.
A good way to validate a form on a server is to only son the table to itself rather than jump to a different page. This allows the user to get an error message on the same form page. Users are also more likely to find errors.

The 16.$_get variable is used to collect values from the form method= "GET".
The $_get variable is an array of variable names and values that are sent by the HTTP GET method.
Information sent from a form with a GET method is visible to anyone (displayed in the browser's address bar) and has a limit (up to 100 characters) to the amount of messages sent.
Note: When using the $_get variable, all variable names and values are displayed in the URL. Therefore, this method should not be used when sending passwords or other sensitive information. However, because the variable is displayed in the URL, you can bookmark the page in the Favorites folder. In some cases, this is useful.

The 17.$_post variable is an array of variable names and values that are sent by the HTTP POST method.
The information sent from a form with a POST method is not visible to anyone (not displayed in the browser's address bar), and there is no limit to the amount of information sent.

The 18.$_request variable contains the contents of $_get, $_post, and $_cookie.
Can be used to obtain the results of form data sent through the GET and POST methods.
However, the page cannot be bookmarked because the variable is not displayed in the URL.

19.Date () function: The timestamp can be formatted as a more readable date and time.
Timestamp refers to the number of seconds since January 1, 1970 (00:00:00 GMT). It is also known as the Unix timestamp (Unix Timestamp).
Special Meanings of letters:
Days of the D – month (01-31)
M – Current month, measured in digital (01-12)
Y – Current year (four digits)
Usage such as:
echo Date ("y/m/d");
echo Date ("Y.M.D");
echo Date ("y-m-d");

20.mktime () function: Gets the Unix timestamp of a date
Syntax: Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
Usage:
$tomorrow = Mktime (0,0,0,date ("M"), Date ("D") +1,date ("Y"));
echo "Tomorrow is". Date ("y/m/d", $tomorrow);

The 21.include and require statements are used to insert the file into another PHP file before the server executes the PHP file.
Include and require are very similar, except for differences in error handling:
Require will generate a fatal error (E_COMPILE_ERROR) and stop the script.
The include will only produce a warning (e_warning) and the script will continue.
Therefore, if you want the script to continue and output the results to the user, even if the containing file is missing, use include. Otherwise, in framework, CMS, or complex PHP application programming, always use require to reference critical files to the execution stream. This helps improve the security and integrity of your application in the event that a critical file is accidentally lost.
The inclusion of files saves a lot of work. This means that you can create a standard header, footer, or menu file for all pages. Then, when the page header needs to be updated, just update the header include file.
Usage:
<div class= "Header" >
<?php include ' header.php ';?>
</div>
In addition, the variables defined in the include file can also be used directly in the calling file

The 22.fopen () function is used to open the file.
Usage:
<?php
$file =fopen ("Test.txt", "R");
?>
R: Read-only. Start at the beginning of the file.
W: Write only. Open and empty the contents of the file, or create a new file if the file does not exist.
A: Append. Opens and writes to the end of the file file, creating a new file if the file does not exist.
X: Write only. Creates a new file. Returns FALSE if the file already exists.
Note: In W, a, and x mode, open files cannot be read!

The fclose () function is used to close open files.

The feof () function detects if the end of the file (EOF) has been reached.
Usage: if (feof ($file)) echo "End of File";

The fgets () function is used to read a file from file to line.
Note: After the function is called, the file pointer moves to the next line.

The fgetc () function is used to read files verbatim from a file.
Note: After the function is called, the file pointer moves to the next character.

23. File Upload form:
The enctype attribute of the <form> tag specifies what type of content to use when submitting a form. Use "Multipart/form-data" when the form requires binary data, such as the contents of a file.
The type= "file" attribute of the <input> tag specifies that the input should be processed as a file. For example, when previewing in a browser, you'll see a browse button next to the input box.
You can add upload restrictions, such as users can only upload. gif or. jpeg files, and the file size must be less than KB:
if (($_files["File" ["type"] = = "Image/gif")
|| ($_files["File" ["type"] = = "Image/jpeg")
|| ($_files["File" ["type"] = = "Image/pjpeg"))
&& ($_files["File" ["Size"] < 20000))
Note: For IE, the type of the recognized JPG file must be pjpeg, and for FireFox, it must be JPEG.

After submitting a file upload form, the server simply creates a temporary copy of the uploaded file.
This temporary copy of the file disappears at the end of the script. To save the uploaded file, we need to copy it to another location:
The Move_uploaded_file () function is used to move uploaded files to a new location

24.cookie: Commonly used to identify users. A cookie is a small file that the server leaves on the user's computer. Whenever the same computer requests a page through a browser, it also sends a cookie.

The Setcookie () function is used to set cookies.
Usage: Setcookie ("User", "David", Time () +3600);
Note: the Setcookie () function must precede the Also, when a cookie is sent, the value of the cookie is automatically URL-encoded and automatically decoded on retrieval (so, to prevent URL encoding, use Setrawcookie () instead).

The $_cookie variable is used to retrieve the value of the COOKIE.

When you want to delete a cookie, you should change the expiration date to a past point in time.
such as: Setcookie ("User", "", Time ()-3600);

The 25.isset () function can be used to detect whether a variable is set
Usage:
<?php
if (Isset ($_cookie["user"))
echo "Welcome". $_cookie["User"]. "!<br/>";
Else
echo "Welcome guest!<br/>";
?>

The 26.session variable is used to store information about a user's session or to change settings for a user session. The Session variable holds information that is single-user and can be used by all pages in the application.
The Session works by creating a unique ID (UID) for each visitor and storing the variables based on this UID. The UID is stored in a cookie or transmitted via a URL.
Before the user information is stored in session, the session must first be started. The user's session is then registered with the server so that user information can begin to be saved and a UID is assigned to the user session.
such as: <?php session_start ();?>
Note: the Session_Start () function must precede the
The correct way to store and retrieve session variables is to use the $_session variable:

The 27.unset () function can be used to release a given variable, such as a session variable.
The Session_destroy () function is used to completely terminate the session:
So if you want to delete some session data, you can use the unset () or Session_destroy () function.
Note: Session_destroy () resets the session and you will lose all stored session data.

The 28.mail () function is used to send e-mail from a script.
Syntax: Mail (to,subject,message,headers,parameters);
To: Required. Specify email recipients.
Subject: Required. Specify the subject of email. Note: This parameter cannot contain any new line characters.
Message: Required. Defines the message to be sent. You should use LF (\ n) to separate the rows.
Headers: Optional. Specify additional headings, such as from, Cc, and BCC. You should use CRLF (\ r \ n) to separate additional headings.
Parameters: Optional. Specify additional parameters for the mail sender.

cc: Copy cc
BCC: Blind carbon copy

The best way to prevent e-mail injection is to validate the input. If using a PHP filter:
The Filter_var () function filters variables by the specified filter.
If successful, returns the filtered data, or false if it fails.
Syntax: Filter_var (variable, filter, options);
Variable: Required. Specifies the variables to filter.
Filter: Optional. Specifies the ID of the filter to be used.
Options: Specifies an array containing the flags/options. Check the possible flags and options for each filter.

Options
Filter_sanitize_email remove illegal characters from a string in an e-mail message
Filter_validate_email Verifying email addresses

Different error handling methods in 29.PHP:
(1) Die () function – equivalent to exit () function: All used to output a message and exit the current script;
(2) Custom error and error triggers;
(3) Error reporting.
Learn more about it later.

30. Abnormal mechanism: The detailed content is understood later.

31.PHP Filter: Learn more about the content later.

The 32.mysql_connect () function is used to open or re-use a connection to a MySQL server.
such as: $con = mysql_connect ("localhost", "root", "Xiandan123″");

The Mysql_error () function returns the text error message generated by the previous MySQL operation.

The Mysql_close () function is used to close the MySQL connection.
such as: Mysql_close ($con);

The mysql_query () function is used to send a MySQL query command. The failure returns false.
such as: mysql_query ("CREATE DATABASE php_db", $con);
or mysql_query ($sql, $con);

The mysql_select_db () function is used to select the MySQL database.
such as: mysql_select_db ("php_db", $con);
Note: Before you create a table, you must first select the database through the mysql_select_db () function.
The SQL statement is not case sensitive.

The Mysql_fetch_array () function is used to get a row from the result set as an associative array, or as a numeric array, or both. Returns an array based on the rows obtained from the result set, or False if there are no more rows. The field names returned by this function are case-sensitive.
Syntax: mysql_fetch_array (Data,array_type);
Data: Optional. Specifies the data pointers to be used. The data pointer is the result of the mysql_query () function.
Array_type: Optional. Specifies what kind of results to return. The possible values are as follows:
mysql_assoc– Associative arrays
mysql_num– Array of numbers
mysql_both– default. Simultaneous generation of associative and numeric arrays
Note: mysql_fetch_array () is an extended version of Mysql_fetch_row (). In addition to storing data as a numeric index in an array, you can store the data as an associated index, using the field name as the key name.
Using Mysql_fetch_array () is not significantly slower than using mysql_fetch_row (), and it clearly provides more values.
Usage:
$result = mysql_query ("SELECT * FROM table_name");
while ($row = Mysql_fetch_array ($result));

The 33.XML file describes the structure of the data.
In XML, there are no predefined tags. You must define your own labels.

XML parser: Reads and updates and creates and processes an XML document on demand.
There are two basic types of XML parsers:
(1) Tree-based parser: This parser transforms an XML document into a tree structure. It parses the entire document and provides an API to access the elements of the tree, such as the Document Object Model (DOM).
(2) Event-based parser: treats an XML document as a series of events. When a specific event occurs, the parser invokes the function to process it.
Event-based parsers focus on the content of XML documents, not their results. Because of this, event-based parsers are able to access data faster than tree-based parsers.
There is no document type declaration (DTD) associated with it, nor is an embedded DTD XML file = Invalid XML.

The Expat parser is an event-based, non-validating parser. Expat is a parser that does not check for validity, ignoring any DTD.

The Xml_parser_create () function is used to create an XML parser.
such as: $parser =xml_parser_create ();

The Xml_set_element_handler () function is used to establish the starting and terminating element handlers. If the processor is successfully established, the function returns True, otherwise false is returned.
Syntax: Xml_set_element_handler (parser,start,end);
Parser: Required. Specifies the XML parser to use.
Start: Required. Specifies the function to invoke at the beginning of the element.
End: Required. Specifies the function that is called at the end of the element.

The Xml_set_character_data_handler () function is used to establish a character data processor. Specifies the function that is called when the parser finds character data in the XML file. If the processor is successfully established, the function returns True, otherwise false is returned.
Syntax: Xml_set_character_data_handler (Parser,handler);
Parser: Required. Specifies the XML parser to use.
Handler: Required. Specifies the function that is used as the event handler.

The Xml_parse () function is used to begin parsing an XML document. Returns true if successful. Otherwise, returns false.
Syntax: Xml_parse (parser,xml,end);

34.SimpleXML is a new feature in PHP 5.
Learn more about it later.

35.AJAX = asynchronous JavaScript and XML.
AJAX is not a new programming language, but just a new cross-platform cross-browser technology.
AJAX uses JavaScript to send and receive data between a Web browser and a Web server. Make the Web page request a small amount of information from the server, rather than the entire page.
With Ajax,web applications, you can send and retrieve data without overloading the Web page. This is done by sending an HTTP request to the server (behind the scenes) and by using JavaScript to modify only a portion of the page when the server returns data.
XML is generally used as a format for receiving server data, although you can use any format, including plain text.

36.XMLHttpRequest object: Is the key to AJAX technology implementation.
Different browsers use different methods to create XMLHttpRequest objects:
IE uses ActiveXObject.
Other browsers use JavaScript built-in objects named XMLHttpRequest.
Workaround:
var xmlhttp=null
if (window. XMLHttpRequest)
{
Xmlhttp=new XMLHttpRequest ()
}
else if (window. ActiveXObject)
{
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP")
}

PHP Learning Notes

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.