Jagand Posted December 27, 2009 Share Posted December 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/ Share on other sites More sharing options...
oni-kun Posted December 27, 2009 Share Posted December 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/#findComment-984452 Share on other sites More sharing options...
Jagand Posted December 27, 2009 Author Share Posted December 27, 2009 $response is a PHP array that I defined in source code. Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/#findComment-984455 Share on other sites More sharing options...
Jagand Posted December 27, 2009 Author Share Posted December 27, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/#findComment-984563 Share on other sites More sharing options...
oni-kun Posted December 27, 2009 Share Posted December 27, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/#findComment-984564 Share on other sites More sharing options...
Jagand Posted December 27, 2009 Author Share Posted December 27, 2009 Oh OK! eva() is working. I am novice and did not knew eval(). Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/186424-problem-replacing-template-variables-in-php-code/#findComment-984574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.