Learning PHP Part 7 : How to Insert PHP Code Into Your HTML

1

PHP provides a variety of ways to insert PHP code into the HTML (I refer to it as a way to get into the mode of PHP). The most popular way is to use an opening tag “<? php” and the closing tag “? >“. However, PHP also provides other ways to enter into the mode of PHP.

As we have learned in the Tutorial Learn PHP: the workings of a web server running PHP code, a PHP file can contain PHP code itself, code HTML and also JavaScript code in a page. Therefore, web servers need a way to tell the Web Server that a section of code is PHP code, not HTML.

How to insert PHP code into HTML

PHP provides 4 ways to get into the mode of PHP.

  1. Standard method (XML Style) PHP

This method is called XML Style because it is based on the writing rules (syntax) eXtensible Markup Language (XML). XML is a markup language that is the basis of xHTML (HTML versions that have more stringent rules). PHP penginputan this method most recommended and most widely used.

To enter into mode PHP, we use a combination of “<?php” as the opening tag and the tag “?>” as the closing tag.

Examples of their use :

2. the method of short tag (SGML Style) PHP

This method is also called with the SGML Style because it is similar to the Standard Generalized Markup Language (SGML). SGML is a markup language standardized format which is the origin of HTML. Called a short tag (PHP Short tags) because this tag is shorter than the XML method. I.e., just using the tag <? As the opening theme for the PHP mode, and tags ?> as tags coverings.

Examples of their use :

In PHP version 5.5 that I use, by default PHP no longer supports the methods SGML Style. However, we can activate it via the PHP settings (php.ini). Discussion about php.ini we discuss in the next tutorial.

3. the method of ASP (ASP Style) PHP

This method is called the method of ASP, as it is similar to the how to enter code ASP to HTML pages. ASP (Active Server Pages) is a web programming language released by Microsoft as a rival of the PHP language.

ASP methods using the tag <% as the opening tag, and tag %> as the closing tag.

Examples of their use :

However, the same as the methods SGML, ASP method is also not supported by default. We have to activate it manually via PHP settings (php.ini).

4. the method of Script (Script Style) PHP

The last method that can be used to enter the mode PHP Script Method is Called, the script method. because of the way writing is similar to other scripting language such as JavaScript and CSS.

The Script methods using the tag <script language=”php”> sebagai tag pembuka, dan tag </script> as a closing tag.

Examples of their use:

The Script method is supported in full by PHP 5.5, however in my experience rarely encountered the PHP code to use this tag.

Instant PHP methods

In addition to the four methods above, there is another way to get into the mode of PHP. The free translation I call it instant PHP, as methods because of the way it combines PHP methods SGML and the command echo in one tag.

The opening tag for the method this is instant PHP <?= and tag ?> as tags coverings.

An example of its use is as follows:

The example above is actually the same as:

Instant method is often used to get into the mode of PHP quickly and does not require a long code.

In its application, instant PHP mode is often used in the making of the form, because it will be easier if you sign in PHP mode at the time required from the entire form created with PHP :

In closing, here is metode_input that contains a summary of the various methods we’ve discussed in this tutorial, but since some methods require setting PHP.ini, you may not be able to run all methods.

The following is a sample display of the results of the program if you have not change the php.ini setting:

webspoint
How to-Enter-into-PHP-code-HTML-PHP-Error

Note that the display is not perfect, because PHP can not process the SMGL Style and ASP Style.

If you already change php.ini values to support the SMGL Style and ASP Style, the result looks into:

webspoint
How to-Enter-into-PHP-code-HTML-input-method-All

Before we discuss more about how PHP, writing on the next tutorial I will discuss about how to edit the php.ini file, where is php.ini PHP configuration file and still related to this tutorial, that we will learn How to enable an ASP method of styling and the SGML Style.

By knowing how to change the default PHP, will make it easier for us to understand how PHP works.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here