Jump to content

Problem replacing template variables in PHP code


Jagand

Recommended Posts

Hi! This post is more related to code logic.

 

I have written a PHP library, templates.inc, which contains classes and is designed to generate header part of the webpage. It's functionality is to fetch data from MySQL and put it into a variable. Content in this variable should then be embedded in the 'source code' of webpage rather than what's currently happening - getting printed on the 'browser'.

 

A part of content variable that I am fetching from template.inc is shown below. This is currently getting printed on browser:

define ("disclaimer","Copyrights © 2009. All Rights Reserved.");

 

Current source code that I wrote to embed fetched data is :

$get_header = new Get_templates;

$response = $get_header->getHeader("main_page");

 

for ($i=0;$i<sizeof($response);$i++):

print $response[$i];

endfor;

 

Can you please suggest on what is the correction? Thanks in advance.

 

Link to comment
Share on other sites

Why on earth are you using this?:

for ($i=0;$i<sizeof($response);$i++):
   print $response[$i];
endfor;

 

You did not tell us what $response is, assuming it's HTML print it, Assuming it's HTML with PHP, than you'd use something such as eval .. You haven't said enough to know what you're wanting to do.

Link to comment
Share on other sites

Ok, I will put my need in a different way. I have written a code that dynamically creates a part of PHP code. It does this through MySQL fetches. I want to embed this dynamically created PHP code into an existing PHP code. How do I do that?

 

What I said, You can use str_replace() to replace the variables by hand into the content, Or use eval to execute PHP code (which is what you're looking to do)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.