问题
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