I have a simple PHP function that outputs HTML.
<?php
function get_header() {
?>
<div id="header">
<div class="page-width">
<!-- And a lot more HTML after this line. -->
<?php
}
?>
So, when I call get_header()
, the function outputs the HTML.
What is the simplest option to tweak this function to return the HTML as a string? Do I need to create a wrapper around this function? In other words, I'd like to be able to do e.g. var html_string = get_header_wrapper()
, where html_string
contains all the HTML above.
One thing I could think of is to duplicate the function and make it return a string. However, that would be so inefficient because it introduces a lot of code duplicate.
<?php
function get_header_wrapper() {
var ret = <<<EOD
<div id="header">
<div class="page-width">
<!-- And a lot more HTML after this line. -->
...
EOD;
return ret;
}
?>