Differencebetween the PHP Open Tags "<=" and "<Php"/"<"

What is the difference between the PHP open tags “ ?=” and “ ?php”/“ ?”?

Rather than talking about whether short_open_tags is deprecated or not we should talk about the advantages and disadvantages when using short open tags:

Advantages

Using the short open tags <? along with <?= is shorter and probably easier to write than the standard opening tags <?php and <?php echo respectively. That’s quite handy when using PHP directly in a template. (That’s probably also the reason why PHP has an alternative syntax for control structures.)

Disadvantages

Requires a specific configuration

When using short open tags you are required to have short_open_tags enabled. If you or your web hosting provider decides to disable short_open_tags, your application probably won’t work any more and you can have some serious security issues. Because if short_open_tags is disabled, only the standard opening tags <?php are recognized and everything inside short opening tags is treated as plain text. (See also the blog post referenced in Sarfraz Ahmed’s answer.)

This requirement makes your PHP application less portable if you aim to write applications that are not just for you. That’a also why many recommend not to use short open tags (including the PHP manual):

Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

As of PHP 5.4 <?= is always available, regardless of the short_open_tags option. <? on the other hand requires the option to be enabled.

Conflicts with XML processing instructions

Another issue is when using XML processing instructions like <?xml … ?>. When short_open_tags is enabled you cannot use them directly in your code but need to use PHP to output it:

If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>.

Otherwise PHP will choke on the xml in <?xml.

Now some last words about the deprecation: Currently short_open_tags is not deprecated. Otherwise the manual would state that explicitly. Additionally, Rasmus Lerdorf, inventor of PHP, wrote in a reply on the question “Is it true that short_open_tag is deprecated in PHP 6?” on the internals mailing list that there were several reasons not to remove short_open_tags in PHP 6:

Which is one of the reasons we decided not to remove them in PHP 6.

Difference between ?php and ?

The first is a safe open and close tag variation, the second is the so called short-open tag. The second one is not always available, use the first option if it's possible.
You could check the availability of short open tags in php.ini, at the short_open_tag.

How to write php without ?php

ANSWER:

Set short_open_tag=On in your php.ini and restart the server.

CAVEAT:

Short open tags are not used according to PHP coding standard PSR-1 which states:

PHP code MUST use the long <?php ?> tags or the short-echo <?= ?> tags; it MUST NOT use the other tag variations.

The reason for this as mentioned by @Magnus Eriksson is that there may be situations where you do not have access to edit the php.ini and therefore code that uses short tags will be rendered unusable in those environments. Adhere to the standard for maximum portability!

Is there a difference between ' ?=' and ' ?php'?

<?= is not the same as <?php

<?= is the same as <?php echo

<? is the same as <?php

PHP short open tag vs long open tag

<?php is the official standard. I've never encountered a problem where a browser was confused, but just using <? can also declare XML and might not be the best habit to form.

I'll tell you this though - other programmers will always appreciate the standard. I would go with <?php for sure.

Difference between ?PHP and ?php

there is no difference. how Sergiu Paraschiv says the tag php is case insensitivi.
Here are the valid ways to open PHP tags

<?php ?> // standard tags
<? ?> // short tags, need short_open_tag enabled in php.ini
<% %> // asp tags, need asp_tags enabled in php.ini

http://www.php.net/manual/en/language.basic-syntax.phptags.php

PHP Implode wrap in tags

In this way you are wrapping the entire set in one span, you have to add the closing/opening tag to the implode:

$value = "<span>".implode('</span>,<span>', $values)."</span>";

Short Open Tag and ?=

Since there is no formal answer, I put together some of the comments, which -in my opinion- actually answer the question:

<?= is no longer considered a short open tag. The reason why <? was discouraged was because it was ambiguous under some situations, i.e <?xml ... ?> or other markup languages.

How to echo in PHP, HTML tags

<?php

echo '<div>
<h3><a href="#">First</a></h3>
<div>Lorem ipsum dolor sit amet.</div>
</div>
<div>';

?>

Just put it in single quotes.



Related Topics



Leave a reply



Submit