blueman378 Posted December 11, 2008 Share Posted December 11, 2008 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 More sharing options...
rhodesa Posted December 11, 2008 Share Posted December 11, 2008 you would need a second include as far as i know. you might be able to run something as the script is terminating with the __destruct magic method in a class. if you are going to start doing templates like this, i would check out Smarty Link to comment https://forums.phpfreaks.com/topic/136455-solved-ob-functions/#findComment-712236 Share on other sites More sharing options...
blueman378 Posted December 11, 2008 Author Share Posted December 11, 2008 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 More sharing options...
rhodesa Posted December 11, 2008 Share Posted December 11, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.