0
<?php
$site= <<< END
   <script src="auto.js"></script>
   <html>
      <body>
        body
      </body>
   </html>
END;
    echo($site);
?>

I try to make a simple php site with JavaScript but the JavaScript does not execute. Where am I wrong? I have the auto.js file in the same dir:

alert("Hello world");
2
  • 4
    Try moving your <script> tag inside of the <body> tag. See if that changes anything. Commented Aug 8, 2013 at 23:53
  • Side note: its not really best practice to use server code to display client side content. You should consider keeping the two separate. Use ajax to bridge the two together. Commented Aug 9, 2013 at 0:05

4 Answers 4

2

try moving the script inside the html.

<?php
$site= <<< END
   <html>
      <script src="auto.js"></script>
      <body>
        body
      </body>
   </html>
END;
    echo($site);
?>

also make sure the js file is in the same folder as your script.

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding quotes around the '$site'.

$site = '<script src="auto.js"></script>
<html>
  <body>
    body
  </body>
</html>';

You can replace echo($site); with echo $site; I'm not sure what the <<< END part is for - I've never seen it before in php.

5 Comments

"I'm not sure what the <<< END part is for - I've never seen it before in php." No offense, but you're not in a position to comment. This is PHP 101.
heredoc syntax does not require quotes
My comment was for Pinch. Heredoc syntax is one of the first things you study in PHP.
I'm a self taught PHP programmer - I might miss a few things. I've been using it for 3 years without having seen this in anyone else's code. Every time I try to help out in this community someone shoots me down. Rest assured, I'll look it up now. David, by 101 he means it's the first thing you should learn in PHP.
@Pinch its a Heredoc syntax. Visit PHP manuals or more details
0

Script tag is outside of the HTML tag.

Comments

0

What is the browser?

In Chrome this is working:

<?php
$site= <<< END
   <script src="auto.js"></script>
   <html>
      <body>
        body
      </body>
   </html>
END;
echo($site);
?>

1 Comment

firefox, works now after moving the script tag inside the html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.