从php页面调用函数

时间:2017-07-24 17:33:01

标签: php html templates

我正在尝试从我主页上的php页面显示html。 我有一个函数在一个名为home-content.php

的php页面中调用一些html
<?php function HomeFeed ($replStr) {
return <<<HTML
  <div class="wider-width">
   <div class="col-full">

    <table class="homefeed1">
    <tbody>
     <tr>
     <td><center><h1>Store Location</h1>
        <h4>Address Line 1<br>
        Address Line 2<br></h4></br><h2><strong>Hours</strong></h2><br>
        <h4>10 AM to 6:30 PM Monday through Friday</h4><br>
        <h4>9 AM to 2 PM Saturday</h4><br
        <h2>Call Now</h2><h4>(903) 769-8043</h4></center>
     </td>
     </tr>
    </tbody>
    </table>
HTML;
}
?>

现在我有我的主页模板,我想调用该函数来显示html。现在,我确定这完全是错的,但我是新手尝试使用php,所以我已经移动了很多东西。我几乎在一点上工作,html正在显示,但它也显示HomeFeed返回&lt;&lt;

<?php
require_once('home-content.php');
?>

HomeFeed()

2 个答案:

答案 0 :(得分:0)

您需要在php转义标记中包装函数调用。您也可以考虑按如下方式修改该功能。

<?php
    require_once('home-content.php');
    HomeFeed();
?>

<?php function HomeFeed () { ?>

  <div class="wider-width">
   <div class="col-full">

    <table class="homefeed1">
    <tbody>
     <tr>
     <td><center><h1>Store Location</h1>
        <h4>Address Line 1<br>
        Address Line 2<br></h4></br><h2><strong>Hours</strong></h2><br>
        <h4>10 AM to 6:30 PM Monday through Friday</h4><br>
        <h4>9 AM to 2 PM Saturday</h4><br
        <h2>Call Now</h2><h4>(903) 769-8043</h4></center>
     </td>
     </tr>
    </tbody>
    </table>

<?php } ?>

答案 1 :(得分:0)

尝试将此字符串赋值给变量并回显它:

将你的函数调用包装在php标签中..

   <?php function HomeFeed () {

$returnstring = <<<HTML
  <div class="wider-width">
   <div class="col-full">

    <table class="homefeed1">
    <tbody>
     <tr>
     <td><center><h1>Store Location</h1>
        <h4>Address Line 1<br>
        Address Line 2<br></h4></br><h2><strong>Hours</strong></h2><br>
        <h4>10 AM to 6:30 PM Monday through Friday</h4><br>
        <h4>9 AM to 2 PM Saturday</h4><br
        <h2>Call Now</h2><h4>(903) 769-8043</h4></center>
     </td>
     </tr>
    </tbody>
    </table>
HTML;
echo $returnstring;
}
?>
    <?php
     require_once('home-content.php');
      HomeFeed();
    ?>