An easy way to embed PHP in HTML, HTML embedded php_php tutorial

Source: Internet
Author: User
Tags echo date

An easy way to embed PHP in HTML, HTML embedded in PHP


We start by learning PHP with an example of submitting orders and displaying order information. This example consists of two files. An HTML file that submits the order: orderform.html, a PHP file that displays the 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 file is organized as shown in the integrated environment that is installed using Xampps.

The HTML file that submits the order is orderform.html as follows:

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

<?php//Create short variable names, also can use ' $_request[' name '] ' $tireqty = $_post[' Tireqty '); $oilqty = $_post[' oil Qty ']; $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 "

"; 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 are Multi line comment. Here are multi line comment. */ ?>

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

Fill in the numbers and click on the "Submit Order" button to submit the content. The page will display an HTML page that processorder.php after parsing the PHP parser, as follows:

In this example, we can learn the following points:

1. The syntax for embedding PHP code in HTML is: <?php code content?>, it should be noted that the start symbol "<?php" cannot have spaces in between.

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

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

Three kinds of quotes function differently:

    • The string in single quotation marks will be output as plain text;
    • If there is a variable in the double quotation mark, 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 contents of the inverted single quotation marks and returns the result after execution.

4. The string can use the dot "." Connected together. In PHP the midpoint is the only String connector, which is equivalent to "+" in Java.

5. There are three types of annotations in PHP: a single-line comment "//" for class Java, a single-line comment "#" For a class shell, and a multiline comment "/**/" for class java.

All variables in 6.php are used with a "$", and the variables are used without the need to declare them in advance.

And the type of the variable can change at any time, depending on the type of value assigned to the variable. The type of PHP variable is determined and changed every time the assignment is evaluated.
The first example of PHP here, I hope you continue to focus on the small part of the article for everyone to organize.

Articles you may be interested in:

    • Get HTML form (HTML form) data using PHP's hyper-variable $_post
    • Parsing the HTML implementation code with PHP
    • Simple principles and methods of generating static HTML in bulk in PHP
    • Using thinkphp to generate static HTML files
    • PHP function sharing for intercepting strings containing HTML tags
    • PHP gets the method of passing an array from an HTML form
    • php5.4 above version GBK encoding htmlspecialchars output is empty problem Resolution summary
    • How to embed PHP code in HTML
    • PHP implementation will upload Word file to HTML method
    • Php method for parsing Web page HTML based on Snoopy

http://www.bkjia.com/PHPjc/1100917.html www.bkjia.com true http://www.bkjia.com/PHPjc/1100917.html techarticle An easy way to embed PHP in HTML, HTML embedded in PHP we started with an example of submitting orders and displaying order information for PHP. This example consists of two files. One to submit the order ...

  • 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.