开发者

In which case can we use <% tag on PHP script ? and inside a $variable?

开发者 https://www.devze.com 2023-03-30 07:04 出处:网络
I just read the php documentation and i read users comments. Instead of <?php, can we have any problems by using :

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 di开发者_开发技巧fferent way ? or it is useless ?

Thank you


<% %> - 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号