Hailwood Posted June 22, 2010 Share Posted June 22, 2010 Hi guys, if i have a variable (lets call it $page for now) and i echo it here (echo $page;) and i include a page here how in the included page can i edit the text that was echoed above? Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/ Share on other sites More sharing options...
trq Posted June 22, 2010 Share Posted June 22, 2010 You can't easily do this, its just not logical. Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/#findComment-1075353 Share on other sites More sharing options...
Hailwood Posted June 22, 2010 Author Share Posted June 22, 2010 then what would you suggest for when you have a default page layout i.e <html> <head> <!--stylsheets here --> <!--javascript here --> </head> <body> <!--header div --> <!-- menu div --> <?php include($_GET['page.php']; ?> <!-- footer div --> </body> and its not pratical for your site to include the header, footer, and menu divs from anther file now in the the include file you want to change the site title, and include another style sheet, so my idea was to have a placeholder variable in the head which i could edit. i am already calling ob_start() at the beginning of every every page so could i use that to edit it? Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/#findComment-1075355 Share on other sites More sharing options...
Hailwood Posted June 22, 2010 Author Share Posted June 22, 2010 see one way i could do it is to call $content = ob_get_contents(); ob_end_clean(); //replace stuff here echo $content; which would work fine, as i could just put ob_start before the echo $content; but is there a tidier way to do this? so the entire thing to replace would actually be $content = ob_get_contents(); $headers = array(); if ( !headers_sent() ) $headers = apache_response_headers(); ob_end_clean(); //replace stuff here ob_start(); if ( !empty( $headers ) ) foreach ( $headers as $name => $value ) header( "$name: $value" ); echo $content; Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/#findComment-1075358 Share on other sites More sharing options...
trq Posted June 22, 2010 Share Posted June 22, 2010 see one way i could do it is to call $content = ob_get_contents(); ob_end_clean(); //replace stuff here echo $content; which would work fine, as i could just put ob_start before the echo $content; but is there a tidier way to do this? That was the only method I had in mind. Not exactly efficient, but it will work. Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/#findComment-1075360 Share on other sites More sharing options...
Hailwood Posted June 22, 2010 Author Share Posted June 22, 2010 damn, i think ill rather rewrite the app than use that on every include... thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/205499-edit-previous-variable/#findComment-1075363 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.