Im new to php and I have a templating system in which I orignally used heredoc syntax but have since decided to get rid of it for a number of reasons.
I have something that looks like this:
public function display_admin() {
return <<<ADMIN_FORM
<form action="{$_SERVER['PHP_SELF']}" enctype="multipart/form-data" method="post">
<label for="title">Title:</label><br />
<input name="title" id="title" type="text" maxlength="220" />
<div class="clear"></div>
<label for="bodytext">Body Text:</label><br />
<textarea name="bodytext" id="bodytext"></textarea>
<input type="submit" value="Create This Entry!" />
</form>
ADMIN_FORM; }
And I call it on a page using this:
$obj = new myCMS();
echo $obj->display_admin();
How can I replace the heredoc syntax? Is there another efficient method for inserting large blocks of HTML into a PHP function? I know there must be a simple solution, here but every time I google it, I get answers that seem better suited for inserting single lines of HTML, not whole blocks.
First of all, there are not much reasons for inserting large blocks of HTML into a PHP function.
calling
$obj->display_admin();makes not much sense.while
makes.
Next, heredoc is absolutely not a templating solution.
While PHP itself is.
So, make a file
admin_form.tpl.phpand just include it where it fits – most likely in your templating class.