Jump to content

PHP in HTM pages


onlyican

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
Link to comment
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.
Link to comment
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

Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.