Renaming *.html to *.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Renaming *.html to *.php

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Renaming *.html to *.php

Post by panic! »

spam.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Renaming *.html to *.php

Post by Vegan »

Not spam, wanted to learn how to use PHP better.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Renaming *.html to *.php

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Renaming *.html to *.php

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Renaming *.html to *.php

Post 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">
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Renaming *.html to *.php

Post 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).
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Renaming *.html to *.php

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Renaming *.html to *.php

Post 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>
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Renaming *.html to *.php

Post 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.
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Renaming *.html to *.php

Post by Syntac »

Like I said, it's a kludgy way of doing something that could easily be done in much more professional a manner.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Renaming *.html to *.php

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Renaming *.html to *.php

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Renaming *.html to *.php

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Renaming *.html to *.php

Post 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. :D
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply