| | |
js php question
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
This is actually a combination js, php, htaccess question so it could go in either one of those categories.
I, like every combo server/client/ajax programmer like to mix my php with my js. I'm just curious about something, I know that you can configure .htaccess to refer to new extensions as something else. Actually let me start here.
Many times I will use external js files but will include them using a php include, for example
which will allow my editor to treat it more like a regular php file rather than a js file. I know it looks dirty if you view source but I never care about that anyway, well actually, maybe I do which is why I am asking this question:
Can I configure apache, through .htaccess to parse a .js file like a .php file. I'm pretty sure it will have no effect on the client, and then I can configure my editor to parse the .js file more like a .php file(for code completion and coloring), and then include it using the standard <script src= include, allowing me to be able to include php in a .js file.
I, like every combo server/client/ajax programmer like to mix my php with my js. I'm just curious about something, I know that you can configure .htaccess to refer to new extensions as something else. Actually let me start here.
Many times I will use external js files but will include them using a php include, for example
include("phpjs/main.js.php"); which will allow my editor to treat it more like a regular php file rather than a js file. I know it looks dirty if you view source but I never care about that anyway, well actually, maybe I do which is why I am asking this question:
Can I configure apache, through .htaccess to parse a .js file like a .php file. I'm pretty sure it will have no effect on the client, and then I can configure my editor to parse the .js file more like a .php file(for code completion and coloring), and then include it using the standard <script src= include, allowing me to be able to include php in a .js file.
Last edited by R0bb0b; Jul 9th, 2008 at 11:23 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Its possible but I wouldn't recommend it. If, down the line, you want to add an actually .js file you'd have to either A) change the file extension or B) add another handler. The quickest way to do this is have all your Javascript in a PHP file then at the top of the file define the content type:
There's nothing saying a script source MUST be .js
php Syntax (Toggle Plain Text)
<?php header("Content-type: text/javascript"); ?> function someJavascriptFunction(){ js1 = <?php echo $blah ?>; }
html Syntax (Toggle Plain Text)
<script type="text/javascript" src="someJS.php"></script>
Last edited by ShawnCplus; Jul 9th, 2008 at 11:43 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
•
•
There's nothing saying a script source MUST be .js
html Syntax (Toggle Plain Text)
<script type="text/javascript" src="someJS.php"></script>
Thx.
Last edited by R0bb0b; Jul 10th, 2008 at 12:13 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
![]() |
Similar Threads
- PHP question regarding Forms (PHP)
- Integrating Php question (PHP)
- PHP question i think! (Site Layout and Usability)
- A php question (PHP)
Other Threads in the PHP Forum
- Previous Thread: Using cookies
- Next Thread: how to format the form textarea?
| Thread Tools | Search this Thread |
action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display domain dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link load login loop mail malfunctioning masterthesis menu mlm multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube






