Php without start/end tags?

Likewise you could make a text file that has a .php extension, and use another, 'real' php file to load that file, such as

Fake PHP file

php_info();

Real PHP file

<?
// file_contents returns a string, which can be processed by eval()
eval(file_get_contents('/path/to/file/'.urldecode($_GET['fakefile'])));
?>

In addition, you could use some mod_rewrite trickery to make the web user feel like they are browsing the php file itself (e.g. http://example.com/fakefile.php)

.htaccess file:

RewrieEngine On
RewriteRule ^(.*)$ realfile.php?fakefile=$1 [QSA]

However, if I remember correctly, your processing will be a little slower, and there are some issues with how evaled code handles $GLOBALS, $_SERVER, $_POST, $_GET, and other vars. You will have to make a global variable to pass these super globals into your evaluated code.

For example:

<?
global $passed_post = $_POST;
// only by converting $_POST into a global variable can it be understood by eval'ed code. 
eval("global $passed_post;\n print_r($passed_post);");
?>

If you'd like to call your PHP script from the command line, you can leave the script tags using the -r switch. Extract from man php:

   -r code        Run PHP code without using script tags ’<?..?>’

Now you can invoke your script in the following manner:

php -r "$(cat foo.php)"

It's better to not use end tag. Begin tag is neccesary.

As MaoTseTongue mentioned, in Zend documentation there is written:

For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.

No. The interpreter needs the tags to know what to parse and what not to.

Tags:

Php