-1

我在一个单独的 php 文件中有一些关于 PHP echo 命令的 HTML 内容。代码如下所示..

  <?php
echo "
    <div id="footer">
        <div id="footer-contact">
                <p><strong>Gardencrafts Heswall Limited</strong> <br> The Nurseries, Lower Thingwall Lane, Thingwall, <br> Wirral CH61 1AZ</p>
                <p><strong>Telephone :</strong> 0151 648 5840</p>
                <p><strong>Fax :</strong> 0151 648 5840</p>
                <p><strong>Email :</strong> gardencrafts1@gmail.com</p>
         </div>
         <div id="footer-icons">
            <div id="social-tab">
                <div id="twitter"><a href='https://twitter.com/GardencraftsUk' class='twitter-follow-button' data-show-count="false">Follow @GardencraftsUk</a></div>
                <div class="fb-like" data-href='https://www.facebook.com/pages/Gardencrafts/200615766704712?fref=ts' data-send="false" data-layout="button_count" data-width="200" data-show-faces="false" data-font="trebuchet ms"></div>
            </div>
            <div id="awards">
                    <img src="images/f1.jpg">
                    <img src="images/f2.jpg">
                    <img src="images/f3.jpg">
            </div>
            <div id="copy">
               <p>Copyright © 2011 Gardencrafts.</p>
            </div>
         </div>
    </div>
";
 ?>

我将其包含在带有以下代码的 php 页面中。

 <?php include("../script/footer.php"); ?>

脚本位于网站根目录中名为 scrpit 的文件夹中。但是当我包含这个时,内容没有显示!谁能帮帮我吗!

谢谢你。

4

6 回答 6

4

您的文件中有语法错误。添加\以转义引号或将它们更改为单个引号:

 <?php
echo "
    <div id=\"footer\">
        <div id=\"footer-contact\">
                <p><strong>Gardencrafts Heswall Limited</strong> <br> The Nurseries, Lower Thingwall Lane, Thingwall, <br> Wirral CH61 1AZ</p>
                <p><strong>Telephone :</strong> 0151 648 5840</p>
                <p><strong>Fax :</strong> 0151 648 5840</p>
                <p><strong>Email :</strong> gardencrafts1@gmail.com</p>
         </div>
         <div id=\"footer-icons\">
            <div id=\"social-tab\">
                <div id=\"twitter\"><a href='https://twitter.com/GardencraftsUk' class='twitter-follow-button' data-show-count=\"false\">Follow @GardencraftsUk</a></div>
                <div class=\"fb-like\" data-href='https://www.facebook.com/pages/Gardencrafts/200615766704712?fref=ts' data-send=\"false\" data-layout=\"button_count\" data-width=\"200\" data-show-faces=\"false\" data-font=\"trebuchet ms\"></div>
            </div>
            <div id=\"awards\">
                    <img src=\"images/f1.jpg\">
                    <img src=\"images/f2.jpg\">
                    <img src=\"images/f3.jpg\">
            </div>
            <div id=\"copy\">
               <p>Copyright © 2011 Gardencrafts.</p>
            </div>
         </div>
    </div>
";
 ?>
于 2013-02-04T08:32:19.060 回答
0

为什么要回显这样的 HTML 块?没有必要这样做。你的路对吗?(你描述的是 include('script/footer.php');)

于 2013-02-04T08:34:08.220 回答
0
 <?php include("script/footer.php"); ?>  

像这样包括你的页脚文件。认为它会帮助你。

于 2013-02-04T08:35:11.487 回答
0

首先在 echo 之后,最后使用单引号而不是双引号,它将起作用,如下所示:

    <?php
echo '
    <div id="footer">
        <div id="footer-contact">
                <p><strong>Gardencrafts Heswall Limited</strong> <br> The Nurseries, Lower Thingwall Lane, Thingwall, <br> Wirral CH61 1AZ</p>
                <p><strong>Telephone :</strong> 0151 648 5840</p>
                <p><strong>Fax :</strong> 0151 648 5840</p>
                <p><strong>Email :</strong> gardencrafts1@gmail.com</p>
         </div>
         <div id="footer-icons">
            <div id="social-tab">
                <div id="twitter"><a href="https://twitter.com/GardencraftsUk" class="twitter-follow-button" data-show-count="false">Follow @GardencraftsUk</a></div>
                <div class="fb-like" data-href="https://www.facebook.com/pages/Gardencrafts/200615766704712?fref=ts" data-send="false" data-layout="button_count" data-width="200" data-show-faces="false" data-font="trebuchet ms"></div>
            </div>
            <div id="awards">
                    <img src="images/f1.jpg">
                    <img src="images/f2.jpg">
                    <img src="images/f3.jpg">
            </div>
            <div id="copy">
               <p>Copyright © 2011 Gardencrafts.</p>
            </div>
         </div>
    </div>
';
 ?>

在里面你只需要有双引号或像 \' 那样转义单引号。

哈哈。或者只是简单地输出没有 echo 的 html 代码,如下所示:

<div id="footer">
    <div id="footer-contact">
            <p><strong>Gardencrafts Heswall Limited</strong> <br> The Nurseries, Lower Thingwall Lane, Thingwall, <br> Wirral CH61 1AZ</p>
            <p><strong>Telephone :</strong> 0151 648 5840</p>
            <p><strong>Fax :</strong> 0151 648 5840</p>
            <p><strong>Email :</strong> gardencrafts1@gmail.com</p>
     </div>
     <div id="footer-icons">
        <div id="social-tab">
            <div id="twitter"><a href="https://twitter.com/GardencraftsUk" class="twitter-follow-button" data-show-count="false">Follow @GardencraftsUk</a></div>
            <div class="fb-like" data-href="https://www.facebook.com/pages/Gardencrafts/200615766704712?fref=ts" data-send="false" data-layout="button_count" data-width="200" data-show-faces="false" data-font="trebuchet ms"></div>
        </div>
        <div id="awards">
                <img src="images/f1.jpg">
                <img src="images/f2.jpg">
                <img src="images/f3.jpg">
        </div>
        <div id="copy">
           <p>Copyright © 2011 Gardencrafts.</p>
        </div>
     </div>
</div>
于 2013-02-04T08:38:43.893 回答
0

你为什么使用 php 标签和 echo ?这样做,只有该页面中的此内容(html)。如果您想在此处使用任何 php 内容,只需添加<?php echo $content; ?>是否需要。

<div id="footer">
    <div id="footer-contact">
            <p><strong>Gardencrafts Heswall Limited</strong> <br> The Nurseries, Lower Thingwall Lane, Thingwall, <br> Wirral CH61 1AZ</p>
            <p><strong>Telephone :</strong> 0151 648 5840</p>
            <p><strong>Fax :</strong> 0151 648 5840</p>
            <p><strong>Email :</strong> gardencrafts1@gmail.com</p>
     </div>
     <div id="footer-icons">
        <div id="social-tab">
            <div id="twitter"><a href='https://twitter.com/GardencraftsUk' class='twitter-follow-button' data-show-count="false">Follow @GardencraftsUk</a></div>
            <div class="fb-like" data-href='https://www.facebook.com/pages/Gardencrafts/200615766704712?fref=ts' data-send="false" data-layout="button_count" data-width="200" data-show-faces="false" data-font="trebuchet ms"></div>
        </div>
        <div id="awards">
                <img src="images/f1.jpg">
                <img src="images/f2.jpg">
                <img src="images/f3.jpg">
        </div>
        <div id="copy">
           <p>Copyright © 2011 Gardencrafts.</p>
        </div>
     </div>
</div>
于 2013-02-04T08:41:41.543 回答
0

尝试在 div 中使用单引号而不是双引号,就像

<?php 
echo "<div id='footer'></div>";

?>

这也可能有帮助。

于 2013-02-04T08:46:23.217 回答