A simple method for Embedding PHP in HTML, and embedding html in php. A simple method for Embedding PHP in HTML. embedding html in php is an example of how to submit an order and display the order information to start learning PHP. This example contains two files. A simple method for Embedding PHP in the HTML of an order submitted, html embedded in php
We started learning PHP with an example of submitting an order and displaying order information. 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.
Articles you may be interested in:
- Use PHP's super variable $ _ POST to obtain HTML Form data
- Use php to parse html implementation code
- Simple principles and methods for generating static HTML in batches using PHP
- Use the built-in thinkphp method to generate static html files
- Php shares functions that intercept strings containing html tags
- Php: how to obtain the array passed from an html form
- Htmlspecialchars output under php5.4 or later GBK encoding is empty problem solution summary
- How to embed PHP code in HTML
- Php implements the method of converting uploaded word files to html
- Php method for parsing webpage html based on Snoopy
In the example of submitting an order and displaying the order information, we start learning PHP. This example contains two files. One order submitted...