0

I know there is an alternative syntax for control structures( PHP Alternate Syntax ). Is there an equivalent for PHP comments? Mainly so comments do not show up in view source. Something like this perhaps.

<?php /* ?>
<h1>THIS WILL NOT SHOW UP ON VIEW SOURCE</h1>
<?php */ ?>

Thanks!

7
  • 2
    Um... Last I checked the code you gave here will produce no output because of the comment... Commented Oct 3, 2013 at 1:27
  • /* anything between these two bookends is considered a comment */ # and prefixing a line with a hash also comments out the line Commented Oct 3, 2013 at 1:28
  • 2
    @DevlshOne # and // do not affect ?> though. /*...*/ does. Commented Oct 3, 2013 at 1:29
  • Good point, although just realised it doesn't really make sense what I am asking and is achieved by just doing. <?php /* <h1>THIS WILL NOT SHOW UP ON VIEW SOURCE</h1> */ ?> Which is shorter any way. Commented Oct 3, 2013 at 1:29
  • 1
    This question appears to be off-topic because the OP could have easily tested their code themselves Commented Oct 3, 2013 at 1:30

1 Answer 1

2

What you have there actually works as expected; alternatively, you can use this as well:

<?php /*
<h1>THIS WILL NOT SHOW UP ON VIEW SOURCE</h1>
*/ ?>

To guard against other code that may appear in between, you could consider using normal control structures with a falsy condition:

<?php if (0): ?>
<h1>THIS WILL NOT SHOW UP ON VIEW SOURCE</h1>
<?php endif; ?>
Sign up to request clarification or add additional context in comments.

1 Comment

@doitlikejustin Any falsy condition, so null, '', array() would all work :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.