Php knowledge accumulation

Source: Internet
Author: User
Php has not been written in native php for a long time. recently, due to a project, it is necessary to involve Native php. It wasn't until now that I even forgot the original statements. I could not say that I was learning php. it was a shame. (Maybe it was because I have been using the framework, and the framework has packaged native knowledge. Alas, I have not learned many things thoroughly.) now I have recorded some problems.

Mutual nesting between php and html: the subconscious only thinks that php is nested in html with many single quotes and double quotes, but it has never been divided by system regions.
(1) embed html tags in php:
Hello World

';?> // Only html code is output
Echo"". $ Val .""; // Html and php code are output together
$ Str =''. $ Val .''; Echo $ str; // assign the content to be output to a variable before outputting the variable

(2) embed php in html
// Use Form output
  • Item No
  • // Output in the form of mixed encoding
    An error was found during SQL statement writing.
    For example:
    $ SQL = "update user set 'username' = $ username, 'password' = $ password ";
    The system will prompt the Unknown column 'yuance' in 'Field list'

    It is only because when the username type is a number, the number itself is inserted, and when the username is a char type, it is equivalent
    Update user set 'username' = yuanfang, 'password' = abd, which is naturally different from SQL. It turns out that such a large xuanjicang is hidden in small details. After learning, it seems that knowledge still comes from nuances. Should be changed

    $ SQL = "update user set 'username' = '$ username', 'password' =' $ password'" or
    $ SQL = "INSERT INTO user (user, pass) values ('". $ user. "', '". $ pass ."')";

    It seems that many of the above questions are about the differences between ''and. Then I further learned the difference between single quotes and double quotes:
    (1) "" fields in double quotation marks are interpreted by the compiler and then output as HTML code. ''Is output directly without being interpreted in single quotes.
    For example:

    -$ Abc = 'My name is tome ';
    -Echo $ abc // The result is: my name is tom.
    -Echo '$ ABC' // The result is: $ abc
    -Echo "$ abc" // The result is: my name is tom.

    Pay attention to the following situations when using single double quotes:
    (1) When outputting a string containing variables:
    $ Username = $ _ POST ['username'];
    To output the following results:

    This is my name + the username received, which can be written as follows:
    -Echo "this is my name $ username"; // $ username will be automatically parsed
    -Echo 'This is my name'. $ username; // output using single quotes
    (2) when using SQL statements
    Since SQL statements must be placed in "", what should I do if there are variables in the SQL statement?
    -$ SQL = "select * from user where username = 'Shine'"; // This is the simplest method.
    -$ SQL = "select * from user where username = '". $ abc ."'";
    The above sentence can be understood as follows:
    1. "SELECT * FROM user WHERE username = '" pure string
    2. connector, used to link the subsequent characters
    3. $ abc display the variable value
    4. single quotation marks (to pair with the first single quotation mark in the condition)
    In fact, it does not need to be so complex. you can write this statement: $ query = "SELECT * FROM user WHERE username = '$ ABC '";
    As you can understand, all the double quotation marks must be parsed by the server. single quotation marks are just common characters.
    (3) $ query = "SELECT * FROM user WHERE username = '". $ abc ["name"]. "'"; // A more complex scenario


    For the first time, I think that small quotes have such a big purpose.

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.