Jump to content

[SOLVED] extract and ob functions


scottybwoy

Recommended Posts

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.

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.