A simple method for Embedding PHP in HTML

Source: Internet
Author: User
Tags php example
This article describes in detail how to embed PHP into HTML by using an instance, if you are interested, you can refer to an example of how to submit an order and display the order information to start learning PHP. This example contains two files. An html file for order submission: orderform.html, and a php file for displaying order information: processorder. php. I put the two files under the test_1 folder and the test_1 folder under the htdocs directory.
The file is organized as shown in. the integrated environment installed with xampps is used.

The HTML file orderform.html for order submission is as follows:

 

The php file processorder. php that displays order information is as follows:

<?php// create short variable names, also can use '$_REQUEST['name']'$tireqty = $_POST['tireqty'];$oilqty = $_POST['oilqty'];$sparkqty = $_POST['sparkqty'];?>  Bob 's Auto Parts - Order Results  Bob 's Auto Parts  Order Results  <?php  echo "

Order processed at "; echo date('H:i, jS F Y')."

"; echo "

Your order is as follows:

"; echo "$tireqty tires
"; echo $oilqty.' bottles of oil
'; echo $sparkqty." spark plugs
" ?> ---------------------------------------------------
<?php $testHeredoc = <<< EOF line 1 line 2 line 3 EOF; echo "$testHeredoc"."
"; ?> ---------------------------------------------------
<?php echo "About Comment:"; //Here is a comment. #Here is a comment too. /* Here is multi line comment. Here is multi line comment. */ ?>

Enter http: // localhost/test_1/orderform.html in the browser. The order information page is displayed, as shown below:

Enter a number and click "Submit Order" to Submit the content. The page displays the html page generated after processorder. php is parsed by the PHP parser, as shown below:

In this example, we can learn the following:

1. the syntax format for Embedding php code in html is: <? Php code content?> Note that the starting symbol "<? Php "cannot contain spaces.

2. the form content submitted by the post method can be obtained by name in the "$ _ POST []" array of php, or by using the "$ _ REQUEST []" array. These arrays are super global variables.

3. a string can be enclosed in single quotes, double quotation marks, or single quotes ~ Is a key ).

The three quotation marks have different effects:

  • Strings in single quotes are output as plain text;
  • If a variable exists in double quotation marks, the variable value is replaced with the variable value and the text is output;
  • The unquoted quotation marks are called execution characters. the php parser first executes the content in the unquoted quotation marks and returns the executed results.

4. strings can be connected by the dot. In php, the dot is a unique string connector, which is equivalent to "+" in java ".

5. php has three annotation methods: Java-like single-line comment "//", shell-like single-line comment "#", and Java-like multi-line comment "/**/".

6. all variables in php are prefixed with "$" and do not need to be declared in advance when using the variables.

The variable type can also be changed at any time, depending on the type of the value assigned to the variable. The php variable type is determined and changed during each assignment.
Here is the first php example. I hope you will continue to pay attention to the articles compiled for you.

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.