This question already has answers here:
<? ?> tags not working in php 5.3.1
(5 answers)
Closed 2 years ago.
I'm trying to install a site locally. Using XAMPP 3.2.3 and php 5.6.
I have an index2.php file which looks like this:
<?
if (2>1)
{
echo 'aa';
}
I open http://localhost/index2.php and see:
1) { echo 'aa'; }
somehow the ">" is interpreted as the end of the php code. How can I make it interpret '>" signs in condition expressions properly? I.e. so the output is
aa
You need to use <?php, not <?, as your script block start.
<? is an XML thing, not a PHP thing.
The <?= syntax is shorthand for <?php echo and is always legal.
But the <? syntax (without the =) is only supported when short_open_tag (in php.ini) is enabled, but this is an obsolete option that is no-longer supported.
Related
This question already has answers here:
is Short tag good practice in php? [duplicate]
(4 answers)
Are PHP short tags acceptable to use?
(28 answers)
How to set short tag(<?) in PHP?
(6 answers)
Closed 3 years ago.
I have used one if condition and i'm using opencart platform
code is working fine in my local but not in the server
<? if ($a == '1') : ?>
// if something
<? else: ?>
// else something
<? endif; ?>
this code giving me an error in my server
i'm using php version 7.2 in both my local and server
Make sure your code to be like this
<?php if ($a == '1') : ?>
// if something
<?php else: ?>
// else something
<?php endif; ?>
short tags are deprecated. short tags depend on an INI directive and as such are non-portable.
If you enable short tags on server then you will not see error.
It is recommended to use if else statemens without short tags.
for more detail about short tags https://wiki.php.net/rfc/deprecate_php_short_tags
This question already has answers here:
How to enable PHP short tags?
(21 answers)
Closed 5 years ago.
im trying to setup my php server to use
<?
echo 'ok';
?>
syntaxis without 'php' inside opening tag. Now my code works like this
<?php
echo 'ok';
?>
How can i achieve this?
I tried to install latest version of php, but it still not working.
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!
You need to edit your php.ini file and turn short_open_tags on
short_open_tag = On
This question already has answers here:
Difference between <?php and <?
(7 answers)
Closed 6 years ago.
I've got some old legacy code written in PHP 5.3.
All PHP blocks in this code are like
<? some_php_code_here ?>
and my Apache just ignores them, while works good with
<?php some_php_code_here ?>
Why old code contains invalid blocks, and why this old code works good on old server ? It's really hard to google something with so much special symbols, sorry for stupid question
<? is called a php short tag
Here is what the manual has to say about it
PHP also allows for short open tag <? (which is discouraged since it
is only available if enabled using the short_open_tag php.ini
configuration file directive, or if PHP was configured with the
--enable-short-tags option).
You can enable them at runtime with <?php ini_set('short_open_tag',1) ?>
But if you do so you won't be able to use inline xml like so <?xml ?>
and instead you can use
<?php echo '<?xml version="1.0"?>'; ?>
As a side note I do often use:
<?= "Hello world" ?>
<?= 'foo' ?> is equivalent to <?php echo 'foo' ?> and looks much cleaner in template files in my opinion
Since php version 5.4, <?= is no longer tied to short_open_tag but prior to that it was, so care should be taken if you might be running your code on older php versions
This question already has answers here:
<? ?> tags not working in php 5.3.1
(5 answers)
Closed 9 years ago.
Note: I'm using PHP 5.3.3 on a CentOS 6 server.
I'm testing out a new web host and I've discovered that it is simply ignoring the <?= $var ?> blocks of PHP code. For instance, if I have this in a PHP file:
<div id='<?=$page_id?>'>
Then it does not display the value of $page_id, it writes it just as you see there. On the other hand, if I write:
<div id='<?php echo $page_id; ?>'>
Then it displays the variable as it should. On its own, this isn't a big deal. Unfortunately I have a TONNE of inherited code that uses the <?= $var ?> syntax all over the place, so I'd like to avoid having to change it all.
Does anyone know what setting I have to change in order for PHP to recognize this syntax? Our old server was running PHP 5.3.14 and it worked fine.
You need to enable short tags.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Reference - What does this symbol mean in PHP?
I don't know if this has been asked before, but here goes: What's the difference between <?php, <?=, and <??
I'm just curious, and people have been telling me to use <?php instead of <?, but I just use <? because it works for me and it's faster. I ain't seein' no diff'rence (redneck accent for extra pleasures...).
<?php and <? are equivalent, except it's generally preferred to use <?php since not every server configuration may have the short opening PHP tags option enabled.
<?= is a shortcut for echoing back the value of a variable/expression, i. e.
<?=$var ?>
is similar to
<?php echo $var; ?>