FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


new to php: can I use php INSIDE html?





Mamsaac
just the question on topic. thanks.
cavey
Yes you can. Just remember to put <?php before the code, and ?> after it. The file should have a php-extension. You can use the html-extension if it is much work renaming all the files, but must then use .htaccess to tell the server to run the html-file as php.
Mamsaac
thanks
Mamsaac
hmmm.

what about html inside php? what would I need to do?
The Conspirator
HTML inside php?
Code:

echo "html here";
ChrisCh
Quote:
You can use the html-extension if it is much work renaming all the files, but must then use .htaccess to tell the server to run the html-file as php.

Hey, do you know how to do that? I've done most of my site with HTML extentions and now that I want to use PHP on most of the pages, it would be quite annoying to have to change them all around!
kv
It will be confusing to run html files as php. It is always better to rename. In windows, you can rename all files in a directory using single command

Code:


ren *.html *.php

golles
I allways use singe quotes for php and double for html, that will keep your code 'clean'

Code:
<?php
echo'<html>
<body code="clean">Trash</body>
</html>';
?>


no trouble with slashes and your php and html won't mess up
cavey
ChrisCh wrote:
Quote:
You can use the html-extension if it is much work renaming all the files, but must then use .htaccess to tell the server to run the html-file as php.

Hey, do you know how to do that? I've done most of my site with HTML extentions and now that I want to use PHP on most of the pages, it would be quite annoying to have to change them all around!


You can write this line in your .htaccess-file to make the server run html-files as php:

Code:
AddType application/x-httpd-php .php .html


If you are not familiar to htaccess-files, maybe this site can teach you something about that: http://www.javascriptkit.com/howto/htaccess.shtml
Mamsaac
all this information was really useful, thanks.
Fire Boar
If you want to put large amounts of html code into php (with an if statement), use this:
Code:

<html>
<head>
<title>Title</title>
</head>
<body>
<?php
// insert code here
if ($var==$whatWeWant) { ?>

<!-- Bung some html in here that you only want displayed if the "if" statement is satisfied -->

<?php }
// more php code as you need it
?>
</body>
</html>

Wink
Related topics
Phoenix free PHP scripts
Difference between PHP and HTML docs
PHP OOP Tutorial
New PHP framework comming up
Inserting data to MYSQL with a PHP script
How to change extension php to html but the php script still
new php version
Rate it - New PHP site...
The best php and html editor?
Parsing PHP in HTML
PHP inside Javascript
asp.net email form
PHP inside HTML tags?
Common IDE Platform for PHP, CSS, HTML and Specially JQuery
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.