I have a class that stores paths to CSS and Javascript files in arrays. This class also compiles my final page HTML output (which is stored in an $output variable). I want to loop through my $css and $js arrays and inject HTML at specific points in $output. The CSS files would need to go right before </head>
and the JS files would need to go right before </body>
Having placeholder $cssFiles and $jsFiles variables within my HTML template files are not an option for me.
And just to complicate this further (sorry), I need a failsafe where if </head>
and/or </body>
do not exist within $output, the code would be injected at the very beginning of $output.
I assume this is a regex problem, but I don't know what the pattern(s) would be.
Thanks!