繁体   English   中英

如何在HTML内部的PHP中注释掉HTML和PHP?

[英]How to comment out both HTML and PHP in PHP inside HTML?

这是我要注释掉的一行代码,

<h1 class="post_title"><a href="<?php the_permalink();?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>

一种流行的注释方式是分别注释掉html和php。

<!--    <h1 class="post_title">
<a href="<?php // the_permalink();?>" title="<?php the_title_attribute(); ?>">
<?php // the_title(); ?></a>
</h1>
-->

有一个更好的方法吗?

<!--    <h1 class="post_title">
<a href="<?php // the_permalink();?>" title="<?php the_title_attribute(); ?>">
<?php // the_title(); ?></a>
</h1>
-->

这将仅注释HTML部分,您将在网页的视图源中找到渲染的PHP代码。

更好的方法..

 <?php /*    <h1 class="post_title">
    <a href="<?php // the_permalink();?>" title="<?php //the_title_attribute(); ?>">
    <?php // the_title(); ?></a>
    </h1>
    */ ?>

尝试这个

<?php 
/*
 * <h1 class="post_title"><a href="<?php the_permalink();?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
 */
?>

有HTML方式...

<!-- commented out stuff -->

...还有PHP的方式...

// for rows only

/* for
   multiple
   rows */

$or = /* for inline */ 'sections';

两者之间的区别在于,虽然HTML方式仍将代码呈现在页面上(可以在浏览器中使用“查看源代码”进行查看),但PHP方式将阻止外界对其进行查看。 只有您或其他允许查看实际文件的程序员才能看到注释掉的片段。

对于该功能,您将必须重构代码。

<?php
//print('<h1 class="post_title"><a href="'. the_permalink() . '" title="' . the_title_attribute() . '">' . the_title() . '</a></h1>');
?>

如果所有代码都在PHP内,则注释掉其中的一部分就变得很容易了,您只需使用PHP的注释规则即可。

如果只想打印来自php函数的结果。 希望对您有所帮助。

<?
$var = //"<h1 class='post_title'><a href=".
    "'php the_permalink()' ".
    //"  title=".
    "'php the_title_attribute() ' ".
    //">".
    "'php the_title()' ".
    //"' </a></h1>";
echo $var;
?>

要么

<?

$var = /*"<h1 class='post_title'>.*/
         /*"<a href='".*/"'php the_permalink()' "./*"  title=".*/"'php the_title_attribute() ' "./*">".*/
             "'php the_title()' ".
        /*"</a>".
    "</h1>"*/;


echo $var;
    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM