Jump to content

[SOLVED] ob functions...


blueman378

Recommended Posts

Hi guys, i know what the ob functions do anyway i was wondering is it possible using them to

 

have say index.php

<?php include("trapcontents.php"); ?>
<html>
<head>
<title><?php echo TITLE; ?></title>
</head>

<body>
<?php echo MY_CONTENT; ?>
</body>
</html>

 

now with code only in trapcontents.php i want to search for the <body> tag and add stuff under it

 

i was thinking i would have to somehow capture the output generated by php, then searcxh that output for the body tag and replace it with <body>WHATEVER I WANTED.

 

is it possible to do all this from one file included in the top of the page or would i be required to add bits and pieces al through the index.php?[/code]

Link to comment
https://forums.phpfreaks.com/topic/136455-solved-ob-functions/
Share on other sites

its not quite a template.

 

its a form generation and validation class.

 

if i need a second include its easier to just tell the user to add the include inside the head section, basically the acctual idea is that the script would add a stylesheet there, but i was trying to avoid a second include.

Link to comment
https://forums.phpfreaks.com/topic/136455-solved-ob-functions/#findComment-712277
Share on other sites

it's not ideal, but this would work:
[codetrapcontents.php]<?php
  class trapper {
    static $instance;
    
    function __construct ( ) {
      if(self::$instance){
        ob_end_clean();
        die("Only one instance allowed");
      }
      self::$instance = $this;
      ob_start();
    }
    
    function __destruct ( ) {
      $contents = ob_get_clean();
      print "Caught Contents:<hr>$contents<hr>";
    }
    
  }
  new trapper();
?>

the __destruct function is where you would modify the contents.

Link to comment
https://forums.phpfreaks.com/topic/136455-solved-ob-functions/#findComment-712604
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.