WinPhan254 WinPhan254 - 3 years ago 69
PHP Question

Call function from php page

I'm trying to display html from a php page on my home page.
I have a function to call some html in a php page called home-content.php

<?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;
}
?>


Now I have my homepage template that I want to call that function to display the html. Now, I'm sure this is all entirely wrong but I'm new to trying to use php, so I've moved thing around a lot and everything. I had it almost working at one point, the html was displaying but it also showed the HomeFeed return <<

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

HomeFeed()

Answer Source

You need to wrap the function call within the php escape tags. Also you might want to consider revising the function as follows.

<?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 } ?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download