如何评论PHP代码

时间:2013-04-01 20:29:21

标签: php comments

我有这段代码

<?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>

我该如何评论?

5 个答案:

答案 0 :(得分:4)

<?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
?>

答案 1 :(得分:0)

像这样:

<?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>
*/ ?>

但我通常删除或替换整个块。

答案 2 :(得分:0)

/ *多行引用* /

对于单行引用,只需在其前键入哈希

答案 3 :(得分:0)

取决于您是否希望将评论传播到浏览器:

<?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>

答案 4 :(得分:0)

您可以通过多种方式在PHP中发表评论:

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

希望它有所帮助。