head - Manipulate HTML page via PHP -
hello have included php file in end of html page. want add style file before end of tag head. need via php file, have no choice.
i have , index.php
file , @ end of file loading script.php
need add script in header of index page using script.php
folder structure:
- index.php
- script.php
the index.php
file have code:
<!doctype html> <html> </head> <body> </body> </html> <?php include "script.php" ?>
how can put in head of html/php when have script.php file @ end of page.
there no direct way this. can think 2 nasty workarounds problem though:
if script has buffering activated (called ob_start somewhere before head closed), string , clean wirh ob_get_clean, insert code , echo again. this:
<?php $output = ob_get_clean(); $output = substr_replace($output, $your_code, strpos($output, '</head>'), 0); echo $output; ?>
since modern browsers quite forgiving, can put style tags after closing html , still work. woudln't though, since it's bad habit
Comments
Post a Comment