I'm trying to modify the contents of the 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 have the $output
but I want to clean all and insert the source of login.php
into the body so that everyone could see my login form ( have css
for the style of website). I have searched on google and only know how to get the content, clean and flush. But I don't see how to modify the buffer contents. Is there a way to modify it?
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.