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 947645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:06:46+00:00 2026-05-15T23:06:46+00:00

I have problem with variable printing inside javascript. variable htmlString printing not working: document.write(htmlString)

  • 0

I have problem with variable printing inside javascript.

variable htmlString printing not working: document.write(htmlString)

<?php  $htmlString= htmlspecialchars(file_get_contents('http://google.com'));?>
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <script type="text/javascript">  
      var htmlString="<?php echo $htmlString; ?>";
      document.write(htmlString);
    </script>

  </body>
</html>


Edit:

Webpage source result: – Get all google.com inside htmlString the var not printed on the page(I cut the all content of htmlString because its very long)

<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <script type="text/javascript">  
      var htmlString="&lt;!doctype html&gt;&lt;html&gt;&lt;head&gt;&lt;metahttp-equiv=&quot;content-type&quot; cotring)";

   document.write(htmlString);
    </script>

  </body>

</html>

Thanks

  • 1 1 Answer
  • 1 View
  • 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-05-15T23:06:46+00:00Added an answer on May 15, 2026 at 11:06 pm

    In order to pull remote pages with file_get_contents it requires fopen_wrappers to be enabled. If your host has this disabled and they allow cURL() I would go that route. cURL is also generally faster then file_get_contents, so that may be a deciding factor as well.

    EDIT:

    The problem you are having, particularly with google, is that it uses JS Code in the webpage. I just var_dump’ed the htmlString and it all displayed fine. But when putting it back into the JavaScript it went caput. The error that came back was an Unterminated String Literal (via Firefox’s Error Console) on Line 8. Probably due to some single quotes etc. In my testing I tried htmlentities(), which worked and displayed the data to the browser. The section to change is:

    
    $htmlString= htmlentities(file_get_contents('http://google.com'));
    

    And it should work like you want it to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem relating to storing a variable within Javascript. I have a
I have a problem with the reference of a variable when loading a saved
I have a problem where a method is getting an undefined variable error, even
I have odd problem: After starting server I got this error: undefined local variable
I am facing problem to get variable from query string. I have used htaccess
I have encountered a most annoying problem that occurs on the PWD variable when
I have a variable named age and a function named AGE. Ignore the problem
I've been have trouble understand this problem. If I change the variable name fifthViewController
I have the following function. The problem is that the $lang variable will vary
I've recently begun learning C# but have encountered an annoying problem. Every variable I

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.