Jump to content


Photo

PHP in HTM pages


  • Please log in to reply
4 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 12 August 2006 - 12:44 PM

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
Tell me the problem, I will try tell you the solution

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 12 August 2006 - 12:53 PM

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

<% %> (I know this is known as ASP, but it works in PHP as well)
<? ?> (Common used)
<?= ?> (forgotten)

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.

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 August 2006 - 12:56 PM

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.javascrip...ternalphp.shtml


Legend has it that reading the manual never killed anyone.
My site

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 12 August 2006 - 02:03 PM

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

Tell me the problem, I will try tell you the solution

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 August 2006 - 03:30 PM

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

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users