View Full Version : Using PHP in external JS file
I have a JS file linked with <script src="...">, which I want to use PHP variables in. Is there any way of doing this? I tried a simple test:
<?php echo "alert('hello world!')" ?>Which gave me a syntax error (the php code was not executed).
Is there something like eval(); that I can use? (Note: I want the file to remain external, it's not the shortest of files)
04-19-2004, 01:54 AM
04-19-2004, 02:38 AM
echo "<script>alert('hello world');</script>";
04-19-2004, 09:29 PM
I think dswimboy is right. If you don't want to rename your file, you'll have to add the .js extension to your server to be parsed as a PHP file.
04-19-2004, 09:52 PM
No, I tested it all you got to do is:
echo ("<script src = 'wahteveritis.js'></script>")
Or the tested thing:
echo ("<script>alert('Hello World')</script>")
04-19-2004, 10:28 PM
in it. Presumes that you're running this on Apache, and have permissions to use .htaccess files. And of course external.js must be the name of the JS file in question.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.