Reading notes: php_tizag_tutorial

Source: Internet
Author: User

Yesterday in the laboratory spent a day to read the English version of the php_tizag_tutorial, because the school period with PHP and Bootstrap wrote a rental site, is more familiar with PHP. Now summarize the Php_tizag_ Tutorial inside some useless or forgotten knowledge points.


1. When you print a string that contains quotation marks, be careful to take one of the following two ways:
1). Precede the quotation marks with a backslash "\".
2). Use single quotation marks.
Examples are as follows:

1<?PHP2 //This won ' t work because of the quotes around specialh5!3 Echo"

;4 //OK because we escaped the quotes!5 Echo"

;6 //OK because we used an apostrophe '7 Echo"

;8?>

2.String Creation Heredoc
Use the <<< and custom identifiers (here is test) to start the heredoc of the string, and finally the "identifier;" As the end flag.
Note that identifiers are on a separate line and cannot be indented.
Examples are as follows:

1 $my _string = <<<TEST2 tizag. com 3 Webmaster Tutorials 4 Unlock your potential! 5 TEST; 6 Echo $my _string;

Output Result:

1 tizag.com Webmaster Tutorials Unlock your potential!

The difference between 3.include function and require function
When using the Include function, if an error occurs, the code is still executed, and the Require function is used, and the execution is aborted.
It is strongly recommended to use the latter.

The difference between 4.POST and get
1). POST
HTML code snippet:

1 <formAction= "process.php"Method= "POST">2 <Selectname= "Item">3 ...4 <inputname= "Quantity"type= "text" />

PHP Code snippet:

1 $quantity $_post [' Quantity ']; 2 $item $_post [' Item '];

2). GET

HTML code snippet:

1 <formAction= "process.php"Method= "Get">2 <Selectname= "Item">3 ...4 <inputname= "Quantity"type= "text" />

PHP Code snippet:

1 $quantity $_get [' Quantity ']; 2 $item $_get [' Item '];

3). Difference between the two

Get pass data is through the URL, the above example jumps to the process.php page is, will be appended to the URL "? item=##&quantity=##", Which? is to tell the browser the next few items are variables. So, send important information such as passwords, etc., Do not use Get method to pass data, this will be completely exposed, very insecure.

5.PHP Creating files
In PHP, the fopen function is used to open a file, and when the file does not exist, the file is created.

1 $ourFileName = "TestFile.txt"; 2 $ourFileHandle fopen ($ourFileNamedie ("Can ' t open file"); 3 fclose ($ourFileHandle);

6.PHP Open File
There are several ways to open a file:
1). Read: ' R '
Read-only, file pointer at the beginning of the file.
2). Write: ' W '
Write only, the file pointer at the beginning of the file. And will overwrite the previous content.
3). Append: ' A '
Write only, the file pointer at the end of the file.

7.PHP Deleting files
Use the unlink function.

1 $myFile = "TestFile.txt"; 2 unlink ($myFile);

8.PHP match field in string
Use the Strpos function to return the corresponding field position.
Examples are as follows:

1 $numberedString // numbers from 1 to 0 2 $fivePos Strpos ($numberedString, "5"); 3 Echo $fivePos";

The results are as follows:

1 string is 423string with Offset

Examples are as follows:

1 $numberedString= "1234567890123456789012345678901234567890";2 $offset= 0;//Initial offset is 03 $fiveCounter= 0;4  while($offset=Strpos($numberedString, "5",$offset+ 1)){5 $fiveCounter++;6 Echo"<br/>five #$fiveCounteris at position-$offset";7}

The results are as follows:

1 #  2#2 are at position-143#3 are at position-24  4#4 is at position-34

9.PHP Split string
Use the Explode function.
Examples are as follows:

1 $rawPhoneNumber= "800-555-5555";2 $phoneChunks=Explode("-",$rawPhoneNumber);3 Echo"Raw Phone number =$rawPhoneNumber<br/> ";4 Echo"First chunk =$phoneChunks[0]<br/>];5 Echo"Second chunk =$phoneChunks[1]<br/>];6 Echo"Third Chunk Chunk =$phoneChunks[2] ";

The results are as follows:

1  number = 800-555-55552 First chunk =3 Second chunk = 5554 third chunk chunk = 5555

10.PHP Connection string
Use the Implode function.

Reading notes: php_tizag_tutorial

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.