scanreg Posted April 8, 2011 Share Posted April 8, 2011 Hi I'd like to call an external js file as a php file, something like: <?php <html><head> <script language=”JavaScript” type=”text/javascript” src=”js.php”></script> </head> <body> </body> </html> ?> I've tried making the js.php file like the following but I get a syntax error: <? Header(”content-type: application/x-javascript”); $testvar=”Hat”; echo “document.write(\”Item: <b>” . $testvar . “</b>\”)”; ?> The error I get is: <br /> <b>Parse error</b>: syntax error, unexpected ':' in <b>/path/to/js/js.php</b> on line <b>2</b><br /> Any idea why it might be triggering this error? Thanks Link to comment https://forums.phpfreaks.com/topic/233102-call-external-javascript-file-as-a-php-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2011 Share Posted April 8, 2011 The quotes that are in the posted code (both pieces) are curly/smart quotes and won't work in php, html tags, or javascript syntax. You need to use straight quotes. Either ' or " Link to comment https://forums.phpfreaks.com/topic/233102-call-external-javascript-file-as-a-php-file/#findComment-1198824 Share on other sites More sharing options...
scanreg Posted April 8, 2011 Author Share Posted April 8, 2011 Ah, eagle eye, thanks Link to comment https://forums.phpfreaks.com/topic/233102-call-external-javascript-file-as-a-php-file/#findComment-1198845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.