Jump to content

Archived

This topic is now archived and is closed to further replies.

onlyican

PHP in HTM pages

Recommended Posts

Hey

I know you can have php code in the following tags

<% %> (I know this is known as ASP, but it works in PHP as well)
<? ?> (Common used)
<?= ?> (forgotten)
<?php ?> (Mainly used with classes)
AND
<script language="php"> </script>

My question

If a website is hosting with a PHP server
Can i have
<script language="php"> </script> in HTM pages, and everything works

Share this post


Link to post
Share on other sites
As far as I'm aware, you can do that if you configure your web server to process .htm files with the PHP interpreter.

[quote author=onlyican link=topic=103976.msg414510#msg414510 date=1155386671]
<% %> (I know this is known as ASP, but it works in PHP as well)
<? ?> (Common used)
<?= ?> (forgotten)
[/quote]
For the above three, I believe they need to be specifically enabled in your php.ini to be usable, not all servers have short tags enabled so they shouldn't be used commonly as you have annotated.

Share this post


Link to post
Share on other sites
The downside to configuring your server to parse .htm files is that it will parse every .htm file whether it needs to or not. That adds server load which you may not want.

A simple alternative which I've used successfully is detailed at http://www.javascriptkit.com/javatutors/externalphp.shtml

Share this post


Link to post
Share on other sites
most servers have
<? ?>
and
<?php ?>

configured as standard
whilst
<% %> and <?= ?> are not normally

if you are using a server with mixed ASP / php then <% %> will not as it is Standard ASP tags

Share this post


Link to post
Share on other sites
[quote author=onlyican link=topic=103976.msg414529#msg414529 date=1155391404]
most servers have
<? ?>
and
<?php ?>

configured as standard
whilst
<% %> and <?= ?> are not normally

if you are using a server with mixed ASP / php then <% %> will not as it is Standard ASP tags

[/quote]
Actually most servers have
<?php and  ?> and,
<script langauge="php"></script>
as standard.

If you want to use <? ?> rather than <?php ?> you'll have to turn on the short_open_tag directive. This directive also allows you to use <?= ?> as shortcut to using <?php echo blah ?>

If you want to use <% %> as PHP tags you'll need to turn on the asp_tags direcitve.

Also note the following tags <? ?>, <% %> and <?= ?> will be removed as of PHP6.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.