Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:38:04+00:00 2026-06-15T10:38:04+00:00

I have en exercise Im working on right now where we can’t use libraries.

  • 0

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:

        <div id="content-wrapper">
            <div id="content">
                <table>
                    <!-- $content -->
                </table>
            </div>
        </div>
    </div>
    <!-- javascript -->
</body>
</html>

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:

$javascript = '<script type="text/javascript" language="javascript" src="../../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);

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:38:06+00:00Added an answer on June 15, 2026 at 10:38 am

    You’re missing a space. Your markup contains:

    <!-- javascript -->
        ^ space here
    

    But your PHP code is missing that space:

    $page   = str_replace('<!--javascript -->', $javascript, $page);
    

    Change it to:

    $page   = str_replace('<!-- javascript -->', $javascript, $page);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an exercise based on this image. I have found the
I have been working on a small exercise for my CIS class and am
I have a code snippet below from an exercise I'm working on. It reads
I have an exercise in problem solving for those who like that kind of
I have recently been working on a exercise in a book I have been
I have this small application that I'm building as an exercise to learn the
I am thinking of working on an online homework submission system where students can
I am working with a Drupal 6.x system to create exercise / personal training
Working on Learn Python the Hard Way exercise 47 and I have the following
I learning to use Pointers. I have a few questions about an exercise code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.