0

I just read the php documentation and i read users comments.

Instead of <?php, can we have any problems by using :

<%
//your php code here
?>

Also i don't really understand a php script on a variable if we turn it into a comment.

<?php
  $file_contents  = '<' . '?php die(); ?' . '>' . "\n";
?>

Do we have another way to "optimize" it or write it into different way ? or it is useless ?

Thank you

Zeroth
  • 83
  • 1
  • 8
  • 1
    The short tags aren't portable. The proper php tags always work, no matter the server's configuration. – Kerrek SB Aug 25 '11 at 00:21
  • (1) Yes, [but](http://stackoverflow.com/questions/3254189/which-php-tags-are-always-available) deprecated. See [php.ini](http://php.net/manual/en/ini.core.php) `asp_tags`. (2) Please reexplain what you were trying to do. – mario Aug 25 '11 at 00:23
  • Thank you ? @mario : just want to know if its possible to use <% without any future problem or just use php – Zeroth Aug 25 '11 at 00:24
  • possible duplicate of [Are PHP short tags acceptable to use?](http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use) – mario Aug 25 '11 at 00:28

1 Answers1

1

<% %> - This type of tags, called ASP-style, are normally used in ASP language.
You can use them in php if you set asp_tags = ON on your php.ini:

ex:

; Allow ASP-style <% %> tags.
; http://www.php.net/manual/en/ini.core.php#ini.asp-tags
asp_tags = ON

Not sure why you would ever use ASP-style tags in php, but they exist... As mentioned by @regality ASP-style tags are Deprecated, this means that they'll no longer be available in future versions of php .

You should always use <? or <?php to start a block of php code and ?> to close it.

ex:

<? echo "I'm learning php"; ?>

or

<?php echo "I'm learning php"; ?>

In regards to your second question, I cannot find much use - if any - for this code:

$file_contents  = '<' . '?php die(); ?' . '>' . "\n";

if you want to get the contents of a file you can use:

$file_contents = file_get_contents('/tmp/examplefile.txt') ;
echo $file_contents;
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • 2
    Good answer, but you may want to include that ASP style tags are deprecated and should no longer be used. – regality Aug 25 '11 at 00:36
  • Thank you, anyway is i want to comment the entire $variable ' . "\n"; ?> I'll get a syntax problem when i'll read ?> do we have better way to write it ? – Zeroth Aug 25 '11 at 00:39
  • What do you want o achieve with `' . "\n"; ?>` ? – Pedro Lobito Aug 25 '11 at 00:40