How to comment php code [closed]

2019-03-07 09:15发布

问题:

I have this code

<?php do_action( 'twentytwelve_credits' ); ?>
        <a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>

How should I comment that?

回答1:

<?php
    echo 'This is a test'; // This is a one-line c++ style comment
    /* This is a multi line comment
       yet another line of comment */
    echo 'This is yet another test';
    echo 'One Final Test'; # This is a one-line shell-style comment
?>


回答2:

like this:

<?php /*do_action( 'twentytwelve_credits' ); ?>
        <a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>
*/ ?>

but i generally delete or replace that entire block.



回答3:

/* multi-line quote */

For a single line quote just type a hash before it



回答4:

Depending on whether you want the comments to be propagated to the browser or not:

<?php 
/* This very interesting comment won't show in the content sent to the browser
 */
do_action( 'twentytwelve_credits' ); 
// or some end of line comment, not forwarded to the browser either
?>
<!--
But this one will
-->
<a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>


回答5:

You can have multiple way to comment in PHP:

/* INFO */ for (multiline comment)
# INFO  for (single line comment)
// INFO for (single line comment)

Hope it helps.



标签: php comments