I have a whole bunch of repetitive link creation code (<a href
). I would like to create a function to call this block of code based on a list of different variables.
The links are inside a table. I have about 15 links almost identical to the one below (the only difference being the Make which in this example is 'FORD') :
Here is the slab of code which is repeated:
<td>
<a href="<?php echo PopulateModel($CategoryId, 1); ?>">
<img src="images/brands/ford.gif" title="Click here if you have a Ford">
</a>
<center>
<a href="<?php echo PopulateModel($CategoryId, 1); ?>" class="make">FORD</a>
</center>
</td>
The Function I want to create is to receive an array of different Models of vehicles, and I want to create a link for each.
I tried using the HEREDOC function in PHP to echo the slab of code via a function but that didn't seem to work. The PHP tags inside of an echo statement seem to be giving errors.
Here is my HEREDOC code (which doesn't work):
function CreateBrandLink($brand_name){
echo <<<EOT
<td><a href="<?php echo PopulateModel($CategoryId, 1); ?>"><img src="images/brands/ford.gif" title="Click here if you have a Ford"></a>
<center><a href="<?php echo PopulateModel($CategoryId, 1); ?>" class="make">FORD</a></center></td>
</td>
EOT;
}