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:

  1. 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; ?> 
  2. since modern browsers quite forgiving, can put style tags after closing html , still work. woudln't though, since it's bad habit


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -