Hanata Hanata - 11 months ago 54
HTML Question

How to modify output buffer?

I'm trying to modify output buffer.
I got something likes this:

if($this->page == 'login')
{
$output = ob_get_contents(); // $output is index.html
// have no idea how to modify `$output`
}


and my
index.html
:

<html>
<head></head>
</body>
if($usr ==null) include 'login.php';
else include main.php; //`main.php` with header bar and footer bar
// this's where i want to clean and insert my login form (login.php)
</body>
</html>


and
login.php
:

<?php
<form>
.....
</form>
?>


I had the
$output
but i want to clean all and insert source of
login.php
into body so that everyone could see my login form ( have
css
for the style of website). I search on google and only know how to get content and cleacn and flush ... But i don't see how to modify. Is there anyway to modify it???
Thanks in advance.

Answer Source

I'm not sure of how the rest of your code works. But maybe you could use a tag to replace with. Something like this.

index.html
<html>
  <head></head>
  </body>
    {{body}}
  </body>
</html>


<?php
//Logic file
if($this->page == 'login')
{
    $output = ob_get_contents();    // $output is index.html 
    ob_clean();
    ob_start();
    include 'login.php';
    $login_content = ob_get_contents();    // $output is index.html  
    ob_clean();
    $content = str_replace('{{body}}', $login_content, $output);

    echo $content;
}