f



Does PHP need the .php extension ?

Hi guys,

When I use PHP I give my file the .php extension. I always wondered if it 
could be an .htm page with a <script> block that the PHP resides in, the 
same way you would do JavaScript. If you can do it that way are there any 
benifits to that method ?

Take care,
Cyrus


0
satan7021 (14)
11/9/2004 4:56:46 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

4 Replies
3023 Views

Similar Articles

[PageSpeed] 26

"Cyrus D." <satan@invalid.org> writes:

> Hi guys,
> 
> When I use PHP I give my file the .php extension. I always wondered if it 
> could be an .htm page with a <script> block that the PHP resides in, the 
> same way you would do JavaScript. If you can do it that way are there any 
> benifits to that method ?
> 
> Take care,
> Cyrus
> 
> 
    Right now you probably have a directive like this in your
httpd.conf file (or your ISP does).

    AddType application/x-httpd-php .php4 .php .php3 .inc .inf .phtml

    It identifies the extensions which should be processed by the
php interpreter before output is sent to the browser.  I believe
you can also include this directive in a .htaccess file in your
area and add .htm to the list. This would send all your files
throught the interpreter and those that do not contain PHP code
would just be passed through....

    You mention Javascript, but that is a bit different.  The
interpretation of that happens at your browser -- all the PHP
work is done at the server.

    Hope this helps.
-- 
                                          John
___________________________________________________________________
John Murtari                              Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211)  "TheBook.Com" (TM)
http://thebook.com/
0
jmurtari (148)
11/9/2004 5:19:41 PM
Cyrus D. wrote:
> Hi guys,
> 
> When I use PHP I give my file the .php extension. I always wondered if it 
> could be an .htm page with a <script> block that the PHP resides in, the 
> same way you would do JavaScript. If you can do it that way are there any 
> benifits to that method ?
> 
> Take care,
> Cyrus
> 
> 


1. You can use the .htm extension and tell the server through .htaccess 
to treat any .htm file as a php file
2. Within a html page (which is treated as php via the above method) you 
can have a php block by surrounding the block with: <?php and ?>

If you like to have a "clean" and easily maintainable site, I would 
personnaly prefer a seperation of languages as much a possible.
In that case there really would be no benefits to using the above method.

Each to their own however, you may find it useful.

J.
0
jrf
11/9/2004 5:22:20 PM
*** Cyrus D. wrote/escribi� (Tue, 09 Nov 2004 16:56:46 GMT):
> When I use PHP I give my file the .php extension. I always wondered if it 
> could be an .htm page with a <script> block that the PHP resides in, the 
> same way you would do JavaScript. If you can do it that way are there any 
> benifits to that method ?

Your web browser must have a rule about what files should be passed to PHP
interpreter (you probably don't want to parse JPEG files ;-) That rule is
normally based in file extension. There's also a tweak called x-bit hack
that works under Unix.


-- 
-- �lvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
0
11/10/2004 1:01:31 PM
 .oO(Alvaro G Vicario)

>*** Cyrus D. wrote/escribi� (Tue, 09 Nov 2004 16:56:46 GMT):
>> When I use PHP I give my file the .php extension. I always wondered if it 
>> could be an .htm page with a <script> block that the PHP resides in, the 
>> same way you would do JavaScript. If you can do it that way are there any 
>> benifits to that method ?
>
>Your web browser must have a rule about what files should be passed to PHP
>interpreter [...]

s/browser/server/

>(you probably don't want to parse JPEG files ;-) That rule is
>normally based in file extension.

Sure, but it's just a matter of configuration. If you want your .foo and
..bar files be handled by PHP - do it. The server does what you tell him
to do.

Micha
0
netizen9733 (527)
11/10/2004 2:52:24 PM
Reply: