2014-10-13 51 views
0

下面是一行代码,我想注释掉,如何在html中注释掉html和php中的内容?

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

有没有更好的方法来做到这一点?请帮忙。

+0

只是用来代码之前,你的代码后使用。 –

+0

使用'Suppr',绝对是注释掉某些代码的最佳方式。 –

+0

为什么我会为这个问题得到满意的结果?对我来说似乎是一个明显的问题。 –

回答

3
<!-- <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> 
    */ ?> 
2

试试这个

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

有HTML方式...

<!-- commented out stuff --> 

...还有就是PHP的方式...

// for rows only 

/* for 
    multiple 
    rows */ 

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

2之间的区别是,虽然HTML的方式仍将在页面上呈现的代码(可通过“查看源代码”来查看在浏览器中),PHP的方式将阻止它被外界查看,即。只有你或其他程序员才能看到实际的文件将会看到注释掉的部分。

0

对于这种功能,你将不得不重构你的代码。

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

如果所有的代码是在PHP然后注释掉一些它变成一件容易的事情,你只会使用PHP的评论规则。

0

如果您只想打印来自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; 
    ?>