Page 1 of 1
Another way of integrating PHP into HTML?
Posted: Sun Feb 08, 2004 4:14 pm
by joetheeskimo5
Is it possible to use the <script> tag in HTML to add a PHP script into the head? Could I make it <script language="PHP"> instead of Javascript?
Thanks for your help.
Posted: Sun Feb 08, 2004 4:19 pm
by DuFF
Straight from
php.net:
The tags supported by PHP are:
Example 5-1. Ways of escaping from HTML
Code: Select all
1. <?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?>
2. <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
<?= expression ?> This is a shortcut for "<? echo expression ?>"
3. <script language="php">
echo ("some editors (like FrontPage) don't
like processing instructions");
</script>
4. <% echo ("You may optionally use ASP-style tags"); %>
<%= $variable; # This is a shortcut for "<% echo . . ." %>
The first way, <?php. . .?>, is the preferred method, as it allows the use of PHP in XML-conformant code such as XHTML.
The second way is not available always. Short tags are available only when they have been enabled. This can be done via the short_tags() function (PHP 3 only), by enabling the short_open_tag configuration setting in the PHP config file, or by compiling PHP with the --enable-short-tags option to configure. Even if it is enabled by default in php.ini-dist, use of short tags are discouraged.
The fourth way is only available if ASP-style tags have been enabled using the asp_tags configuration setting.
Note: Support for ASP-style tags was added in 3.0.4.
Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.
The closing tag for the block will include the immediately trailing newline if one is present. Also, the closing tag automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. Closing tag of a PHP block at the end of a file is optional.
So, yes, you can.
Posted: Sun Feb 08, 2004 8:00 pm
by joetheeskimo5
Thanks a lot.

Posted: Mon Feb 09, 2004 3:02 am
by Dr Evil
I fail to see the point. <?php and ?> are the standard. Moving away from it just makes things more complicated, when you migrate or distribute your code.
????
Posted: Mon Feb 09, 2004 5:33 am
by joetheeskimo5
I was just wondering if PHP could be a script and appear in the header. I'm probably not going to bother to use it anyway.