How can I properly outcomment this PHP code? [closed]

我的未来我决定 提交于 2019-12-02 23:57:04

问题


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 outcomment 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:


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>



回答3:


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.




回答4:


/* multi-line quote */

For a single line quote just type a hash (#) before it.




回答5:


You have multiple ways to comment in PHP:

/* INFO */ for multiline comments
# INFO  for single-line comments
// INFO for single-line comments


来源:https://stackoverflow.com/questions/15751294/how-can-i-properly-outcomment-this-php-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!