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

  • Home
  • SEARCH
  • 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 8928267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:23:54+00:00 2026-06-15T08:23:54+00:00

I have a template .php file with a bunch of functions in it to

  • 0

I have a template .php file with a bunch of functions in it to render out html. Here is a snippet:

$j ='    
table("tb_02", "600", "", "ebebeb", "right", "top", "30 0 30 0","Table content...");
//whole bunch of similar functions here...
';

The table function looks like this:

    function table($tbID, $tbWidth, $tbHeight, $tbBgColor, $tbHzAlign, $tbVtAlign, $tbPad, $tbContent) {
// code omitted here     
$a = "
          <table id=\"$tbID\" width=\"$tbWidth\" $tbHeight $tbBgColor border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
            <tr>
              <td valign=\"$tbVtAlign\" align=\"$tbHzAlign\" width=\"$tbWidth\" style=\"$pad\">
        $tbContent
              </td>
            </tr>
          </table>  
        "; 
          echo $a;
        };

What I want to do is turn the result of $j in the template .php file (which will be html only – no php) into a string. The issue I’m having is that I first need it eval’d (the result of the functions, and then convert that). I’m after something like this, but can’t find a way to get the eval’d code back to a string:

$j = eval($j);
$j = str_replace("<", "&lt;", $j);
$j = str_replace(">", "&gt;", $j);
echo $j;

Thanks for the help!

  • 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-06-15T08:23:55+00:00Added an answer on June 15, 2026 at 8:23 am

    eval is not a templating system. It’s slow, unsafe, and shouldn’t be used. There is always a better way to do things.

    I suggest looking around for a real templating system, what you are doing is very bad practice.

    First off, your functions should be returning data, not echoing it. That way, you can manipulate it, and echo it out all at once.

    Second, have a look at HEREDOCs, they’ll make your life easier.

    function table($tbID, $tbWidth, $tbHeight, $tbBgColor, $tbHzAlign, $tbVtAlign, $tbPad, $tbContent) {
        // code omitted here     
        $a = <<<HTML
        <table id="$tbID" width="$tbWidth" $tbHeight $tbBgColor border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="$tbVtAlign" align="$tbHzAlign" width="$tbWidth" style="$pad">$tbContent</td>
            </tr>
        </table>
    HTML;
    
        return $a;
    }
    

    Lastly, you shouldn’t be trying to eval strings, it’s pad practice. My suggestion may not be any better practice, but it’s better than eval.

    Instead of $j being a string, try making it an array.

    $j = array(
        'table' => array("tb_02", "600", "", "ebebeb", "right", "top", "30 0 30 0","Table content...")
    );
    

    Now what you can do, is use call_user_func_array to “eval” the code.

    $html = '';
    
    foreach($j as $func=>$args){
        $x = call_user_func_array($func, $args);
    
        $x = str_replace("<", "&lt;", $x);
        $x = str_replace(">", "&gt;", $x);
    
        $html .= $x;
    }
    
    echo $html;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template in joomla without index.php I only have index.html, css file,
I have a php file and a bunch of HTML elements that include: header
example i have a file template.php with: <table> <tr> <td><?php echo $data['nombre'] ?></td> </tr>
I have a index.php file that will include several external files: content/templates/id1/template.php content/templates/id2/template.php content/templates/id3/template.php
I have this code which will include template.php file from inside each of these
Have a form here with bunch of input text fields and a file upload
I have a WordPress template that contains the following element: <html xmlns=http://www.w3.org/1999/xhtml <?php language_attributes('xhtml');
Let's assume I have the following file - template.php : <?php $string = 'Hello
I have a template.php file with a theme called themename_status_messages It's not being called/invoked
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',

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.