php.ini: what i must change, to write <? instead <?php? - php

in my local hosting the script doesn't work, if i wrote <? instead of <?php.
what i must change in php.ini to correct it?
Thanks

http://php.net/manual/en/ini.core.php
short_open_tag
Is the property you seek.

It is:
short_open_tag
Make sure to read:
PHP Short Open Tag: Convenient Shortcut or Short Changing Security?

It's already been said how to do it, but I'm just saying that it might not be such a great idea. Almost anyone you ask will tell you not to use short tags. Unless you have a specific reason to use short tags, you should just type <?php. It's only 3 more characters.

Related

Is it now safe to use PHP echo short tags?

Is it now totally and completely safe to use
<?=$var ?>
instead of
<?php echo $var; ?>
I wouldn't use the words "totally" and "completely", but with PHP5.4 the "short-open-and-echo"-syntax is part of the core and thus always available. Remind, that I only talk about <?= ?> and not the "regular" short-open-tags <? ?>.
Yes. As of PHP 5.4.0 from 01-Mar-2012 you can use short tag. From php 5.4 change log,
<?= is now always available regardless of the short_open_tag setting.
This was a General improvement.
So if you have PHP 5.4 you can use <?= syntax.
Yes. There is no real issue with using <?=$var?>, but if you want to be totally prepared for a host that doesn't have this enabled, then you may want to write it using full statement.
Typically, you can enable this feature even if it's disabled.
It's better to always use the regular <?php tag. That way you are sure that your scripts are always compatible with any PHP installation, regardless of the PHP version or php.ini settings.
Even more important if you are developing code that's meant to be shared, such as a library.
ref: http://php.net/ChangeLog.php#5.4.32
"short open tag is now always available regardless of the short_open_tagsetting"
Yes. As of PHP 5.4, echo tags are always enabled unless your host disables them.

What are these PHP tags called?

Instead of <?php print $somevar; ?> you can write <?= $somevar; ?>.
The reason I ask is that my php configuration does not seem to be evaluating these and I need to know the name so I can change php.ini.
They are called short-tags
Oh, and keep in mind, short tags have been said to be deprecated in 6 and will be removed later (I haven't been able to find a working link, sorry)... There's some distention among the community about this, so time will tell...
Short open tags
As others said, they're called short_open_tags . Relying on these is considered "bad" because it depends on a INI setting and affects your code's portability.
Open or short tags
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; 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.
short_open_tag = On
short_open_tags = On or Off in php.ini

Question mark equals, doesn't work on php

this is my php code:
<html><body>Hey!: <?= "World";?></body></html>
It just prints "Hey!:" Whats wrong with my code?
Short tags (which you're using here) can be turned on or off depending on the server you're running the code on. If it's your server, look in php.ini
You need to set short_open_tag to 1
http://php.net/manual/en/ini.core.php
Does your file end in .php and will it execute as php on your webserver? add
<?php echo "yes I run php!<br>\n"; ?>
to your file to be sure. View source to see what happened to the php tags. Then maybe switch on short tags as the other answers told you to.

<? or <?php --- is there any difference? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Are PHP short tags acceptable to use?
What does “<?=” mean when seen in PHP
is there any difference in using <? ?> to signify a php block, or using <?php ?> ?
if there is not, why would anyone use <?php ?
figure the file extension of .php would give plenty of info about what type of code you are looking at.
The first is called short-open tags and second one is safe open and close tags.
You could enable/disable short open tags in php.ini using short_open_tag setting.
The short tags should be avoided, have a look at:
PHP Short Open Tag: Convenient Shortcut or Short Changing Security?
Servers must be configured to also use <?, so it is considered best practice to use <?php for portability reasons.
From the manual ( http://www.php.net/manual/en/language.basic-syntax.phpmode.php ):
There are four different pairs of
opening and closing tags which can be
used in PHP. Two of those,
and ,
are always available. The other two
are short tags and ASP style tags, and
can be turned on and off from the
php.ini configuration file. As such,
while some people find short tags and
ASP style tags convenient, they are
less portable, and generally not
recommended.
<?php can always be used. <? can only be used if the short_open_tag directive is turned on.
short_open_tag tells PHP whether the short form (<? ?>) of PHP's open tag should be allowed. 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"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).
Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.
-- Description of core php.ini directives
As others have mentioned, this directive is often turned off so for portability reasons I prefer using <?php ?>. If this is not an issue, there shouldn't be much difference other than that if the directive is turned on you can also use the <?= shorthand thingy.
I have never personally run into this issue, but support for <? ?> is spotty when moving to different servers. I prefer to just stick to <?php ?> for clarity and consistency.
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.
And also note that if you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.
Always use <?php ?> because <? ?>:
will not work in coming PHP versions
could be mixed with XML definitions. (XML always starts with <?xml ...)
is not enabled on many shared hosting sites.
short tags <? ?> , only work in older php versions.
There is no difference language-wise, but many shop prefer the use of <?php because the simple <? opening tag can be found in XML files, which can lead to confusion for the interpreter.
Edit: I thought this was still an issue: http://terrychay.com/article/short_open_tag.shtml

PHP. "?>" on top of page

I am creating site with php.
On localhost all works well.
On my hosting all looks good too, but on top of page i see "?>". In my code these symbols are absent.
What is this?
It could be that your code uses short open tags (<? instead of <?php) and your hosting provider has short open tags turned off. That would mean, however, that your PHP code is not interpreted at all. It could also mean that your hosting provider doesn't support PHP at all, or only for certain file types.
Take a look into the page's source code to check whether that is the case.
The fact that you see that on top of the page could mean one or more things.
It seems you have typed in ?>
outside of a php block
You may be using short tags <?
instead of long <?php and the host
has short tags turned off
Out of these its most likely you have a closing ?> in your code without a corresponding open <?php tag
Are you sure yu're seeing ?> and not something like >>? ?
Otherwise, this smells like a PHP-EndTag which was never opened...check your code.
If you have a empty lines in your sourcefile before the opening <?php-tag, then those empty lines could get outputted unintenionally. If your script should start with <?php on top, remove all the empty lines above it.

Categories