Reading notes: php_tizag_tutorial spent a day in the lab yesterday reading the English version of php_tizag_tutorial, because I used php and bootstrap to write a rental website last semester and I am still familiar with php. now, let's sum up some things that have never been used or forgotten in php_tizag_tutorial.
1. when the printed string contains quotation marks, pay attention to one of the following two methods:
1). add the backslash "\" before the quotation marks "\".
2). use single quotes.
Example:
1
2. String Creation Heredoc
Use < <和自定义的一些标识符(这里用的是test)开始字符串的heredoc,最后以"标识符;"作为结束标志.
Note that the identifier must be in a single row and cannot be indented.
Example:
1 $ my_string = <
Output result:
1 Tizag.com Webmaster Tutorials Unlock your potential!
3. differences between the include function and the require function
When the include function is used, if an error occurs, it only raises a warning and the code is still executed. when the require function is used, an error is reported and execution is terminated.
The latter is strongly recommended.
4. differences between POST and GET
1). POST
HTML code snippet:
1
2
3 ...4
PHP code snippet:
1 $quantity = $_POST['quantity'];2 $item = $_POST['item'];
2). GET
HTML code snippet:
1 2 3 ...4
PHP code snippet:
1 $quantity = $_GET['quantity'];2 $item = $_GET['item'];
3). differences between the two
GET transmits data through a url. in the preceding example, the process. php page is displayed, and "?" is attached to the url "? Item ### & quantity ### ", where? This is to tell the browser that the following variables are variables. Therefore, when passing important information such as passwords, do not use the GET method to transmit data. This will completely expose and will be very insecure.
5. create a file in PHP
In PHP, the fopen function is used to open a file. when the file does not exist, the file is created.
1 $ourFileName = "testFile.txt";2 $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");3 fclose($ourFileHandle);
6. open the file in PHP
There are several ways to open a file:
1). Read: 'R'
Read-only. the file pointer starts with the file.
2). Write: 'W'
Write-only. the file pointer starts with the file and overwrites the previous content.
3). Append: 'A'
Write-only. the file pointer is at the end of the file.
7. delete files in PHP
Use the unlink function.
1 $myFile = "testFile.txt";2 unlink($myFile);
8. PHP matches fields in strings
Use the strpos function to return the corresponding field location.
Example:
1 $numberedString = "1234567890"; // 10 numbers from 1 to 02 $fivePos = strpos($numberedString, "5");3 echo "The position of 5 in our string was $fivePos";
The result is as follows:
1 The position of 5 in our string was 42 3 Finding All Occurrences in a String with Offset
Example:
1 $numberedString = "1234567890123456789012345678901234567890";2 $offset = 0; // initial offset is 03 $fiveCounter = 0;4 while($offset = strpos($numberedString, "5", $offset + 1)){5 $fiveCounter++;6 echo "
Five #$fiveCounter is at position - $offset";7 }
The result is as follows:
1 Five #1 is at position - 4 2 Five #2 is at position - 143 Five #3 is at position - 244 Five #4 is at position - 34
9. PHP split string
Use the explode function.
Example:
1 $rawPhoneNumber = "800-555-5555";2 $phoneChunks = explode("-", $rawPhoneNumber);3 echo "Raw Phone Number = $rawPhoneNumber
";4 echo "First chunk = $phoneChunks[0]
";5 echo "Second chunk = $phoneChunks[1]
";6 echo "Third Chunk chunk = $phoneChunks[2]";
The result is as follows:
1 Raw Phone Number = 800-555-55552 First chunk = 8003 Second chunk = 5554 Third Chunk chunk = 5555
10. PHP connection string
Use the implode function.