Code is not executed on command line

Asked

Viewed 63 times

5

I have a file teste.php with the following code.

 <?
 echo "teste";
 ?>

When I run the command on the terminal php -f teste.php I receive as output my code:

 <?
 echo "teste";
 ?>

instead of:

teste

What’s going on?

  • 2

    Try opening the normal <php tags? ?>

1 answer

5


The problem lies in your opening tags <?

To use them you need to enable in the configuration of php.ini the option short_tags_open for on. More information on this configuration here.

On the other hand, it is highly ill-advised the use of short_tags_open as they may conflict with the file header XML (<?xml version="1.0"?>).

So much so that this configuration can be removed in future version in PHP, as is the case with ASP style tags <% %> (configuration asp_tags)

In short

Utilize <?php in all your scripts.

It is safer because it will work on any PHP server, it will not be removed in the future and you will not have headaches when working with XML.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.