开发者

Commenting php tags

开发者 https://www.devze.com 2023-02-19 16:09 出处:网络
I got this code below from a tutorial I\'m using to learn PHP.I know that // is used to comment out code. In the first line of the code below, you see{// subject selected ?>

I got this code below from a tutorial I'm using to learn PHP. I know that // is used to comment out code. In the first line of the code below, you see {// subject selected ?>

Is the php tag ?>开发者_如何学C not commented out by the // along with the subject selected text?

<?php if (!is_null($sel_subject)) {// subject selected ?>
<h2><?php echo   $sel_subject['menu_name'];?></h2>
<?php } elseif (!is_null($sel_page)) {// page selected ?>
<h2><?php echo $sel_page['menu_name']; ?></h2>
<?php } else { // nothing selected ?>
<h2>Select a subject or page to edit</h2>
<?php } ?>


the BEST place to address such questions is an official man page:

The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ... ?> or # ... ?> WILL be printed: ?> breaks out of PHP mode and returns to HTML mode, and // or # cannot influence that.

I can assure you that it's way more reliable source of knowledge than some volunteered help from some enthusiast


No, ?> is not commented out.


no ?> are not commented out with the in line comment, where as the block comment they are.

http://codepad.org/YUhG2DTd

Example: The following ?> does not get commented out.

<?php
\\?>

echo 'works';
?>

where as the following does get commented out.

<?php
/*
?>
*/

echo 'failed';
?>


{// subject selected ?>

No, the ?> is not commented. Because, that is not part of a php statement. That is a tag that apache uses to determine. Apache will send the contents enclosed by the tags to php and place the output from php in its output buffer.

0

精彩评论

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