i have a set of JavaScript files in /js directory.
how to add PHP tags to Javascript File ?
i have a set of JavaScript files in /js directory. how to add PHP
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Exactly the same way you add them to any other text file. Open them in a text editor and start typing
<?php etc.You need to make sure that PHP is used to process the files though. That is done, most easily, on most systems, by renaming them to have a
.phpfile extension. You can also change your webserver’s configuration.If they are going to emit JavaScript, then you should make sure that they claim to be JavaScript, and not HTML (the default for PHP).
It is typical that JavaScript files are sent with cache control headers that encourage heavy caching. If you add dynamic content to them, then be prepared to lose the benefits of that caching. If appropriate, use PHP to send suitable cache control headers with the JS.
You may wish to consider keeping your logic in static JavaScript files and use PHP to just inject some dynamic data into a
<script>element directly into the HTML document.