Is it possible to add a <script> tag into HTML with PHP str_replace?

KasynoLodoreer

New Member
I have en exercise Im working on right now where we can't use libraries. I have a REST based system that instantiates different PHP classes depending on what needs to be done. I have several HTML files that are loaded into PHP and then using str_replace I switch out the variables I want to inject into the HTML. I now want to add a tag at the end of one of my HTML files. My ../../html/body.html file looks like this:\[code\] <div id="content-wrapper"> <div id="content"> <table> <!-- $content --> </table> </div> </div> </div> <!-- javascript --></body></html>\[/code\]I use this "body" page several times so the " $content " varies depending on what I replace them with in PHP.Now for some reason when I try to replace javascript with a script tag it doesn't work. Heres my PHP that is trying to do this:\[code\]$javascript = '<script type="text/javascript" language="javascript" src="http://stackoverflow.com/js/subscriber.js"></script>';$page = file_get_contents("../../html/body.html");$head = file_get_contents("../../html/doctype.html");$nav = file_get_contents("../../html/Navbar.html");$page = str_replace('<!--javascript -->', $javascript, $page);$page = str_replace('<!-- $content -->', $theFeed, $page);$nav = str_replace('<!-- $name -->', $this->user, $nav);$nav = str_replace('$user', $this->you, $nav);$nav = str_replace('$key', $this->key, $nav);$nav = str_replace('$picUrl', $picUrl, $nav);echo($head);echo($nav);echo($page);\[/code\]I was thinking that this way I only need to include scripts on the necesarry pages or not at all if the page doesn't need any javascript. Does PHP or HTML block script tags somehow? Im not sure how to get around this. Thanks!
 
Back
Top