why some php code doesn't have "php" in "<?php" [duplicate] - php

This question already has answers here:
Are PHP short tags acceptable to use?
(28 answers)
Closed 9 years ago.
I know this is probably a noob question but I really can't figure this out.
I was ask to modify the existing php code so I downloaded the code and try running on my machine but i can't get it to work.
from my understand we write php code in
<?php
//some code
?>
but this code that i downloaded uses php code like this
<?
//some code
?>
It doesn't work on my machine but it works on the production server.
Does anyone know how this works?
Update:
Looking at the code in details, this is example of the code
<?php include $_SERVER["DOCUMENT_ROOT"]."/pages/layouts/summary.php"; ?>
then in summary.php
<?
session_start();
require_once $_SERVER["DOCUMENT_ROOT"]."/includes/mysql.php";
require_once $_SERVER["DOCUMENT_ROOT"]."/includes/functions.php";
//more code ...
?>

When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser.
PHP also allows for short tags <? and ?> (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option.
Read here http://php.net/manual/en/language.basic-syntax.phptags.php

; http://php.net/short-open-tag
short_open_tag = Off
Open short tag from php.ini file
short_open_tag = on

if short_open_tag is set to on in the php.ini file then we can use instead of
but its madatory to use if short_open_tags are set to off in the php.ini file.This is off on default

Related

php have some rules with the open tag <? ?>? [duplicate]

This question already has answers here:
How to enable PHP short tags?
(21 answers)
Closed 1 year ago.
I have an application that has some PHP code, the PHP open/close tag I'm using is:
<?
$anything;
echo problem;
?>
The application is not running.
Are there some rules for this type of open/close ( maybe a php.ini config.) that might cause the application not to run ?
P.S. Would the better way be to change all <? to <?php ?
run a phpinfo(), look for the path which php.ini is used. Then open the file and find short_open_tag
Set it to on or off.
But in general.. use <?php ?> this is better.
Use <?php ?>. <? ?> are referred to as short-tags, and not every server is setup to support them.
The <? version of the open tag is called a "short tag." While the php community prefers the use of the full <?php version of this tag, it is still acceptable to use short tags. Ideally, we would all use <?php all the time, but we often deal with legacy code, and changing all occurrences of <? to <?php can be tedious and time consuming. If you find yourself in a situation where you need to allow the php interpreter to recognize the short tag, you may enable it in the php.ini file using the "short_open_tag=1" directive.
For new code you are developing, I would recommend using the long version of the tag <?php, as you know that will be compatible regardless of the ini setting used in the servers php.ini config. For more information on this, see: Are Php Short Tags Acceptable To Use here on StackOverflow.
To figure out why your application is not running, check the webserver error logs, as well as the php error logs, and consider turning up php's error reporting level. This can also be done in the php.ini file using the error_reporting directive. This will allow you to determine what is causing the application to not run, and then you will be more informed for further questions.
You should use <?php ?> to ensure correct parsing.
There are specific times where it is suited or possible to use the short tags like this for PHP
<?=$sign['last_connected']?>
notice the <?= instead of <?php echo

php file with <? ?> tags in XAMPP [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to enable PHP short tags ?
Hi
I have Xampp version 1.7.3. While browsing a project it shows error. This is because my php code starts with <?....?> so I want to execute my project with both the <? ..... ?> tag and <?php ....?> tag.
Thanks
You are searching for the short_open_tag directive ;-)
To indicate PHP it should accept <? ... ?> as valid PHP tags, you must put this in your php.ini file :
short_open_tag = On
Instead of what you currently have :
short_open_tag = Off
Notes :
You can find out where your php.ini file is using phpinfo().
Generally speaking, you should not use short open tags, as those can be disabled (you've just seen that)
Set short_open_tag = on in your php.ini.
You could also use php_flag short_open_tag on on your .htaccess file.
However, you should use <?php as that cannot be disabled!
Don't do it man... <?php is guaranteed valid on any server running PHP. As a trade off for the extra 3 characters, you can omit the closing ?> ... see manual for details.
http://php.net/manual/en/language.basic-syntax.instruction-separation.php

does PHP Version 5.3.2 work without <?php woth with <?

i have one complete website
which was written in php4, now my hosting server is PHP Version 5.3.2, windows 2008 server
and my site is not working, what i found is old site use following syntax
<?
but if i change it into
<?php
page start working. is there any way to solve this issue...
PHP Version 5.3.2 work with
<?
any script which change all
<? to <?php
in all pages.
This is not down to the PHP version, but depends on the short_open_tag php.ini setting.
You can change the ini setting to "1", but the use of short open tags is generally discouraged these days.
Short tags are a discouraged feature of PHP. You should convert all <? to <?php, because as of PHP 6.0, they will be deprecated. (This is partially to better support XML documents, which have a tag that starts with <?)
BTW, you can turn them on in your configuration.
the following code snippet helped me convert all short tags to proper PHP tags, hope it helps you too:
REPLACING SHORT TAGS WITH PROPER PHP TAGS (archived copy)
There is a directive in your php.ini file called "short_open_tag". This is what allows you to use the shorthand or not. They should not be used anymore though, so its better if you update all tags to the new format.
Metropolis

PHP arrow operator closing tags

I am writing a php app on the websever I set up at my house. It is a fedora10 machine, running php5 and mysql. I have code like this:
<?php echo $var->function(); ?>
But for some reason the -> is closing the php tag, so the output has 'function(); ?' added to it...is there something I need to change in my php or webserver configuration?
I dont think that you have mod_php enabled in your apache config file, or else you would never see the php code in the output. Here is a good tutorial on setting up php 5 in apache.
Try
<?php echo("foo"); ?>
If that doesn't work, you don't have PHP enabled in Apache.
If your're sure that php is enabled, try this one
<?php
$result = $var -> function();
echo $result;
?>
to debug it a little.. maybe something interesting will raise
Is the php enabled on server? A simple test for determining it:
<?php phpinfo();?>
Put the above line in a .php file and access it.
You could also try this:
<?php phpinfo();
Final closing php tag isn't required.
I ran into a similar problem the other day but I was using
bar ?>
instead of
bar; ?>
It turned out that the short_open_tag option was disabled in my PHP configuration.
I had the same problem with a standard XAMPP installation.
short_open_tag=On
Solved it.

Why is "<?" no longer working and instead only "<?php" works?

I was using xampp to develop locally and then I installed the PHP from the direct installer. Now in some of my PHP code, only PHP code that starts with "<?php" is correctly parsed. Anything that starts with "<?" or "<?=" is completely ignored and just left as is.
How can I adjust the configuration to parse either tokens?
This is a php.ini setting named
short_open_tag = 1 # (enabled)
I recommend you to disable short_open_tag and only work with <?php. When short_open_tag is enabled, it can collide with the XML processing instruction <?xml as both the PHP open tag and XML PI start with a <?.
By using only <? as start preprocessor startup, you can get the preprocessor confused with well formed XML documents. XML stands <? for processing-instruction, imagine an XHTML document with embeded XML that requires XSLT processing... The preprocessor will get confused with the stylesheet processing instruction and will throw an error.
It's higly recomended to use the <?php processor starting tag, try using the
short_open_tag = Off in your php.ini. Also, you can try using <?php ini_set('short_open_tag', 'On'); > if you are getting problems.
You can set short_open_tag = On in the php.ini
It's a configuration option, more information on: http://www.php.net/ini.core (look for short_open_tag).
For the newer version:
short_open_tag = On

Categories