PHP, unlike some other languages, works with the source code being written in the same file as the HTML code. In .NET languages, for example, a .class file distinguishes what will be viewed by the user (HTML) and which is effectively read and interpreted by the server.
However, so there is the correct interpretation of the source code, you must indicate to the server the beginning and the end of the source code so that there is information processing.
When PHP parses a file, it looks for opening and closing tags, which indicate when to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all kinds of documents, as everything outside of a pair of opening and closing tags is ignored by the PHP interpreter.
<p> This will be ignored.</p>
<?php echo ‘While this will be interpreted.’; ?>
<p> This will also be ignored.</p>
This kind of behavior works as expected, because when PHP hits the parameter “?>” closing tags, it simply starts sending to output anything it finds until you find another opening tag. The example given above is contrived, of course, but is also used to write large blocks of text.
There are two pairs of opening and closing tags that can be used with PHP. As such, “<? Php?>” and “<script language =” php “> </ script>. Any of them can be used at any time. There are still other two are short tags and ASP-style tags, which can be turned on and off from the php.ini configuration file. So, while some people find short tags and ASP style tags in convenient, they are less portable, and generally not recommended.
1. <?php echo ‘if you want to serve XHTML or XML documents, do like this’; ?>
2. <script language=”php”>
echo ‘some editors (like FrontPage) do not
they like processing instructions’;
3. <? echo ‘this is the simplest, an SGML processing instruction’; ?>
<?= expression ?> This is a shortcut for “<? Echo expression ?>”
4. <% echo ‘You can optionally use ASP-style tags’; %>
<%= $variable; # This is a shortcut for “<% echo . . .” %>
While the tags seen in examples one and two are always available for use, example one is the most commonly used and recommended among them.
While the tags seen in examples one and two are always available for use, example one is the most commonly used and recommended among them
Tags in ASP style (example four) is only available when they are enabled by asp_tags configuration directive in php.ini.