<?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");
asked Aug 8, 2013 at 23:50
The D Merged
7001 gold badge9 silver badges17 bronze badges
4 Answers 4
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.
answered Aug 8, 2013 at 23:58
castis
8,2144 gold badges45 silver badges66 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
castis
heredoc syntax does not require quotes
Pinch
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.
AgentSQL
@Pinch its a Heredoc syntax. Visit PHP manuals or more details
Script tag is outside of the HTML tag.
Comments
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);
?>
answered Aug 9, 2013 at 0:06
Federico Bucchi
541 silver badge5 bronze badges
1 Comment
The D Merged
firefox, works now after moving the script tag inside the html.
default
<script>tag inside of the<body>tag. See if that changes anything.