PHP正在评论我的HTML ID?

时间:2016-06-02 21:09:13

标签: php

我是PHP的新手。当我的代码命中ID标签时,它正在评论我的代码。我怎么能覆盖这个呢?感谢。

<?php echo "<!-- Contact Section -->
<section id="contact" class="contact-section">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h4 style="font-weight:bold;margin-bottom:20px;margin-top:0;">Begin Your Partnership with Us and Compare <i>ALL</i> of your Business Funding Options</h4>
                <a href="#scroll-ref" class="page-scroll btn btn-success"><i>Get Started with the Quick Quote Process Now!</i></a>
            </div>
        </div>
    </div>
</section>";
?>

2 个答案:

答案 0 :(得分:1)

为您的属性使用单引号,因为您对echo字符串使用双引号。

说明

基本上,您在echo之后终止了<section id=语句,因为您对属性值使用了相同的引用。

您有两种选择:

  1. 转义字符串\"contact\"
  2. 中的双引号
  3. 只需使用单引号'contact'

答案 1 :(得分:0)

使用heredoc语法:

<?php echo <<<HTML
<!-- Contact Section -->
<section id="contact" class="contact-section">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h4>Begin Your Partnership with Us and Compare <i>ALL</i> of your Business Funding Options</h4>
                <a href="#scroll-ref" class="page-scroll btn btn-success"><i>Get Started with the Quick Quote Process Now!</i></a>
            </div>
        </div>
    </div>
</section>
HTML;
?>

... echo声明的单引号:

<?php echo '
<!-- Contact Section -->
<section id="contact" class="contact-section">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h4>Begin Your Partnership with Us and Compare <i>ALL</i> of your Business Funding Options</h4>
                <a href="#scroll-ref" class="page-scroll btn btn-success"><i>Get Started with the Quick Quote Process Now!</i></a>
            </div>
        </div>
    </div>
</section>
';
?>

...或将HTML代码放在PHP之外:

<?php
// PHP code
?>
<!-- Contact Section -->
<section id="contact" class="contact-section">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h4>Begin Your Partnership with Us and Compare <i>ALL</i> of your Business Funding Options</h4>
                <a href="#scroll-ref" class="page-scroll btn btn-success"><i>Get Started with the Quick Quote Process Now!</i></a>
            </div>
        </div>
    </div>
</section>
<?php
// More PHP code
?>

除了这些之外还有其他几个选项,但它们通常不太可读。