Page 1 of 2
Renaming *.html to *.php
Posted: Fri Oct 24, 2008 11:09 am
by Vegan
Reviewing PHP reveals such code is always wrapped inside a pair of tags. Does this mean a wholesale renaming of all of my HTML files to PHP will work and allow me to incrementally add PHP functions as needed?
So given a standard HTML document, then I can use PHP to manage ads more effectively as new ones come to be available.
I have a simple ad-rotator now in PHP so leveraging the code snippet into a HTML code base would be nirvana.
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 11:32 am
by panic!
spam.
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 11:59 am
by Vegan
Not spam, wanted to learn how to use PHP better.
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 12:09 pm
by requinix
panic! wrote:spam.
And how is that?
PHP files are a subset of HTML files. Almost all HTML files can be PHP files, PHP files can't generally be HTML files.
The "almost" is because of the
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
you need for XHTML documents.
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 12:18 pm
by onion2k
Hmm.. I can see where panic! is coming from. There are a whole lot of links in your sig. But I don't think this is spam so I'm not going to take any action.
Just for the record, if you're hoping those links will help your search engine position ... Googlebot doesn't see anyone's signature so they won't be helping at all.
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 1:46 pm
by Vegan
OK in all of my pages at present, I am using XHTML transitional as some of the ads I have now are using iframes, others are IMG others are javascript, etc. So I have a real mixed bag of code, and was hoping that Apache can figure out how to paste in an ad rotator widget so I an change ads randomly to make the sites a tad more dynamic.
I am new to PHP so forgive my ignorance, one I get a better grip on it I will be able function better and get the ball rolling to a more generally well design system.
Once the ads are finished, I was looking at installing some stock quotes and was hoping a PHP widget was available for the econ site.
This forum seemed to have some potential so hence I wanted to see if a pure XHTML can be renamed and then add code when needed. I am new to Linux and Apache, coming from a Windows platform.
As for the Google bot, there is also MSN, Yahoo etc. All junk. Curiously though my use of phpBB3 has a screen that shows who actually comes to visit my forums so it begs the question as to what does it really do?
Here are my document headers that I use now.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="
http://www.w3.org/1999/xhtml" lang="en_us">
Re: Renaming *.html to *.php
Posted: Fri Oct 24, 2008 5:05 pm
by Syntac
Just change the extensions. Although, in theory, you could set up Apache to process .html files as well as .php files (this method is kludgy, so don't do it unless you have to).
Re: Renaming *.html to *.php
Posted: Sat Oct 25, 2008 9:49 am
by Vegan
Thanks, I will try that out and see how long it lasts before I come back here.
PHP seems to have some potential so I am slowly learning how to use it.
Re: Renaming *.html to *.php
Posted: Sat Oct 25, 2008 1:51 pm
by JAB Creations
This is insanely simple...
1.) Do
not rename your file extensions from HTML to PHP. This is bad for SEO.
2.) To execute PHP on HTML files do the following...
.htaccess
AddType application/x-httpd-php .txt .html
3.) You will have to echo the XML declaration...
Code: Select all
<?php
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
Re: Renaming *.html to *.php
Posted: Sat Oct 25, 2008 2:12 pm
by onion2k
JAB Creations wrote:2.) To execute PHP on HTML files do the following...
.htaccess
AddType application/x-httpd-php .txt .html
You should be careful doing that. All the .txt and .html files will have to be parsed by PHP. If you have static files that don't contain any code they'll take a lot more resources on the server to be sent to the user. On an extremely busy website that's a very bad thing.
Re: Renaming *.html to *.php
Posted: Sat Oct 25, 2008 3:40 pm
by Syntac
Like I said, it's a kludgy way of doing something that could easily be done in much more professional a manner.
Re: Renaming *.html to *.php
Posted: Sun Oct 26, 2008 10:53 am
by Vegan
What would you suggest? I could create a new *.pho and redirect the *.html easy enough. That would keep broken links at bay.
The whole idea behind my question is to better display ads and with LAMP that means PHP gets the job.
<?php
$fcontents = join ('', file ('banner_ads.txt'));
$s_con = split("~",$fcontents);
$banner_no = rand(0,(count($s_con)-1));
echo $s_con[$banner_no];
?>
In the banner-ads.txt file, put an ad on each line, and separate them with the ~ on a new line by itself. You can wrap the code in a <div> and apply any CSS style you need such as centering the ad etc.
This code can handle zillions of ads. Short, and exactly what I wanted to install.
Later when I get more skilled I wanted to move the text file to MySQL and pull ads from the database. But that is another project.
The goal with this code is to have a random ad on document footers. This code does that easily.
Re: Renaming *.html to *.php
Posted: Sun Oct 26, 2008 11:01 am
by Syntac
I wasn't saying what you were doing was kludgy... I was just saying that setting Apache to process .html files as PHP isn't ideal.
Re: Renaming *.html to *.php
Posted: Sun Oct 26, 2008 11:03 pm
by Vegan
Well I am influenced unduly by phpBB as a platform with a lot of potential. So I speculated that PHP would be adequate to post ads in my content. All the better to temp users.
Re: Renaming *.html to *.php
Posted: Sun Oct 26, 2008 11:38 pm
by s.dot
There's a bunch of crap in this topic, LOL. Well not necessarily crap, but just beating around the bush.
Just rename your .html extensions to .php extensions and you can put php code in any of them.

Simple.

Don't worry about the .htaccess part, or search engine ranking.
I've had fairly busy web sites (upwards of 200,000 page loads per day) on a pretty normal server and server load never became a problem. I've also had .php pages rank well (and yes, in google).
Keep it simple.
