【问题标题】:How can I properly outcomment this PHP code? [closed]我怎样才能正确地评价这个 PHP 代码? [关闭]
【发布时间】:2013-03-22 23:46:47
【问题描述】:

我有这个代码:

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

我应该如何评价它?

【问题讨论】:

    标签: php comments


    【解决方案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】:

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

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

      像这样:

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

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

      【讨论】:

        【解决方案4】:

        在 PHP 中有多种注释方式:

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

        【讨论】:

          【解决方案5】:
          /* multi-line quote */
          

          对于单行引号,只需在其前面输入一个哈希 (#) 或双斜杠 (//)。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-09-03
            • 2014-07-23
            • 2016-06-15
            • 2021-09-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多