Home > Article > Backend Development > Code start sign type in php php7 php environment construction php from entry to proficiency
When I was looking at other people’s php code today, I found
<code><span><span><?php </span><span>$a</span>=<span>'test'</span>; <span>?></span></span><span><span></span>=<span>$a</span><span>?></span></span></span></code>
that the result actually outputted ‘test’
So I changed the code to the following: The
<code><span><span><?php </span><span>$a</span>=<span>'test'</span>; <span>?></span></span><span><span></span><span>echo</span><span>$a</span><span>?></span></span></span></code>
structure had nothing, so I became even more curious. Start looking for information and so on. . .
Online information: ?>
is a short tag, <?php ?>
is a long tag, end tags are generally rarely used, the command =
, which is the same as echo
is equivalent, but short_open_tag needs to be turned on before use.
What is short_open_tag?
Determines whether the abbreviated form of the code start flag ( ?>
) is allowed.
It can be configured in php.ini.
Problem: I checked my php.ini configuration file and found that short_open_tag was not turned on. As shown below:
But why can I still use =
Could it be that there are multiple php.ini, I don’t know, so I checked it through phpinfo();
Found short_open_tag = Off.
So =
Why can it be used but still can’t be solved?
So I will start short_open_tag, that is, set short_open_tag = On, and then restart the server. Found that
<code><span><span></span><span>echo</span><span>'hello'</span>; <span>?></span></span></code>
can output results.
Summary: It turns out that short_open_tag controls the ?>
tag. Instead of the = ?>
tag, the = ?>
tag is used for output variables. When short_open_tag is enabled, ?>
has the same function as <?php ?>
.
If asp_tags = ON is set, then we can still play like this
<code>$a=<span>'hello'</span>; <span>echo</span><span>$a</span>; %></code>
Remarks: The php version used is: PHP Version 5.5.12
Now to summarize, there are several opening and closing tags in PHP
<?php
?>
= ?> ;
The above introduces the code start flag types in PHP, including PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.