scottybwoy Posted December 2, 2008 Share Posted December 2, 2008 Hi, I have a small script that's used for templating. It's meant to extract $vars out of an object, read a file (.php with html syntax, except php placeholders like so <?=$var?>). Then pass the contents to an echo. It takes the vars, but they don't get entered into the placeholders. Are there any settings in the php.ini I need to change or am I just doing it wrong. Here's the code : <?php function fetch($file) { print_r($this->vars); ob_start(); // Start output buffering extract($this->vars); // Extract the vars to local namespace include($this->path . $file); // Include the file $contents = ob_get_contents(); // Get the contents of the buffer ob_end_clean(); // End buffering and discard return $contents; // Return the contents } ?> The print_r echos : Array ( [title] => I Say Union, You Say Onion ) Let's say the file being passed has this contents : <html> <head> <title><?=$title?></title> </head> <body> This page has a title of <?=$title?>. </body> </html> When $contents is echoes in the calling file, it just prints "Array ( [title] => I Say Union, You Say Onion )This page has a title of ." Without putting the title in. This is the first time I've used these functions so would be helpful for your clarification. Quote Link to comment https://forums.phpfreaks.com/topic/135244-solved-extract-and-ob-functions/ Share on other sites More sharing options...
DarkWater Posted December 2, 2008 Share Posted December 2, 2008 Don't use short tags. Quote Link to comment https://forums.phpfreaks.com/topic/135244-solved-extract-and-ob-functions/#findComment-704444 Share on other sites More sharing options...
scottybwoy Posted December 2, 2008 Author Share Posted December 2, 2008 Could have sworn I tried that, lol. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135244-solved-extract-and-ob-functions/#findComment-704472 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.