Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4115722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:37:07+00:00 2026-05-20T22:37:07+00:00

Im new to php and I have a templating system in which I orignally

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:37:08+00:00Added an answer on May 20, 2026 at 10:37 pm

    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

    $data = array('bodytext' => $text);
    $obj->set_data($data);
    $obj->set_template('admin_form')
    $obj->display();
    

    makes.

    Next, heredoc is absolutely not a templating solution.
    While PHP itself is.

    So, make a file admin_form.tpl.php

    <form action="" 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"><?=$data['bodytext']?></textarea>
    <? if ($data['id']): ?>
      <input name="id" id="id" type="hidden" value="<?=$data['id']?>" />
    <? endif ?>
      <input type="submit" value="Create This Entry!" />
    </form>
    

    and just include it where it fits – most likely in your templating class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to php and am asking for some coding help. I have
I'm new to PHP, and I can't figure out this basic question. Does PHP
I have enabled PHP 5.3.2 and Apache 2.2.14 on my install of Mac OS
In the new PHP SDK is there any way to post to a friends
I'm trying to figure out a way to do the following with php: Have
I am working on a simplistic website using PHP, a language I haven't touched
I have a mysql code that needs to be improved because of my limited
I have a little problem because I don't know whats the best way to
I am trying to create a user login/creation script in PHP and would like
Ok I creating an application that needs to query records from my remote database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.