Simple way to embed PHP in HTML _php tips

Source: Internet
Author: User
Tags echo date php code

We take an example of submitting an order and displaying order information for the start of learning PHP. This example contains two files. An HTML file that submits an order: orderform.html, a PHP file that displays order information: processorder.php. I placed the two files under the Test_1 folder and placed the Test_1 folder under the Htdocs directory.
The document is organized as shown in the following illustration, using the integrated environment installed by Xampps.

The HTML file orderform.html to submit the order is as follows:

<form action= "processorder.php" method= "POST" >
  <table>
    <tr bgcolor= "#cccccc" >
      < TD width= "<TD" >Item</td>
      width= ">Quantity</td>
    </tr>
    <tr>"
      <td>Tires</td>
      <td align= "center" ><input type= "text" name= "Tireqty" size= "3" Maxlength= "3"/></td>
    </tr>
    <tr>
      <td>Oil</td>
      <td align= " Center "><input type=" text "name=" Oilqty "size=" 3 "maxlength=" 3 "/></td>
    </tr>
    <tr >
      <td>spark plugs</td>
      <td align= "center" ><input type= "text" name= "sparkqty" size = "3" maxlength= "3"/></td>
    </tr>
    <tr>
      <td colspan= "2" align= "Center" > <input type= "Submit" value= "Submit Order"/></td>
    </tr>
  </table>
</form >

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

<?php//Create short variable names, also can use ' $_request[' name '] ' $tireqty = $_post[' Tireqty '];
$oilqty = $_post[' Oilqty ']; $sparkqty = $_post[' Sparkqty '];?> <! DOCTYPE html>  

Entering http://localhost/test_1/orderform.html in the browser will display the Fill order Information page as follows:

Fill in the number and then click the Submit Order button to commit the content. The page will display the HTML page generated by the processorder.php after parsing the PHP parser, as follows:

In this example, we can learn from the following points:

1. The syntax format for embedding PHP code in HTML is: <?php code content?>, it should be noted that the beginning of the symbol "<?php" can not have spaces in the middle.

2. The content of the form submitted by the POST method can be obtained by name in the "$_post[]" array of PHP, or by the "$_request[" array. These arrays are super global variables.

3. Strings can be enclosed in single quotes or double quotes, or in inverted single quotes (inverted single quotes in the upper-left corner of the keyboard, and ~ is a key).

Three kinds of quotes are different:

    • The string within the single quotation mark is to be exported as plain text;
    • If a variable is in double quotes, the value of the variable is replaced and the text is output;
    • The inverted single quote is called the executor, and the PHP parser executes the inverted single quotation mark and returns the result after execution.

4. The string can use the dot number "." are connected together. The PHP midpoint number is a unique string connector, equivalent to "+" in Java.

5. There are three annotation modes in PHP: One-class Java single line annotation "//"; class Shell's single-line annotation "#"; Java multiline annotation "/**/".

All variables in 6.php are used with "$", and the variable is not required to be declared in advance when used.

The type of the variable can also change at any time, depending on the type of value assigned to the variable. The type of the PHP variable is determined and changed each time the value is assigned.
The first example of PHP to say here, I hope you will continue to focus on small series for everyone to organize the article.

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.