0

How would I go about commenting all of this code when it has breaks in the PHP sections?

If I wrap /* */ around it, it doesn't work.

Obviously I can make it work by not being lazy, but if I want to be lazy... How might you comment this whole block?

if($fields){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php
                                /* if($field['label']){
                                    echo $field['label'];
                                } */
                                print_ext($field);
                            ?>
                        </li>
                    <?php
                }
            ?>
        </ul>
    <?php
}
7
  • Do you mean comment out the HTML so that it doesn't display? Commented Aug 7, 2012 at 15:59
  • 1
    I wonder if you could use HEREDOC to assign it all to some unused variable. Commented Aug 7, 2012 at 16:00
  • He cant just comment the html because of the ?> it would still mean commenting every line as he switches back and forth between HTML and PHP Commented Aug 7, 2012 at 16:01
  • 1
    Comment out the HTML right before and after it (<!-- -->). This will hide the HTML and anything generated by the PHP. Commented Aug 7, 2012 at 16:01
  • But it will also mean running the php.. which is no good.. But thanks for the try :) Commented Aug 7, 2012 at 16:04

4 Answers 4

4

You can't really but you can turn it off pretty easily.

if($fields && false){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php 
                                /*if($field['label']){
                                    echo $field['label'];
                                }*/
                                print_ext($field); 
                            ?>
                        </li>
                    <?php                                                        
                }
            ?>
        </ul>
    <?php
} 
Sign up to request clarification or add additional context in comments.

Comments

1

The following solution should work. You might have issues if you are wrapping the comments that exist already around if($field['label']) so I have deleted them as shown below.

<?php
/*
if($fields){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php 
                                if($field['label']){
                                    echo $field['label'];
                                }
                                print_ext($field); 
                            ?>
                        </li>
                    <?php                                                        
                }
            ?>
        </ul>
    <?php
} 
*/
?>

For more information look at this answer.

1 Comment

Can you elaborate on why (or if the poster has left the building, somebody else - we no longer have this information)? Nested comments are not allowed? Link to authoritative documentation that states it? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the question/answer should appear as if it was written today).
0

Put your HTML within the PHP open/close tags and then the /* */ will work fine.

Comments

0

Not really commenting, but you can disable this block like this (almost no matter its content):

<?php $bar = <<<'EOD'
if($fields && false){
  ?>
    <ul>
    <?php
    foreach($fields as $field){
      ?>
        <li>
        <?php
        /*if($field['label']){
          echo $field['label'];
          }*/
        print_ext($field);
      ?>
        </li>
        <?php
    }
  ?>
    </ul>
    <?php
}
EOD;

1 Comment

Doesn't your EOD; have to go on its own line?

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.