Current location: Hot Scripts Forums » Programming Languages » PHP » PHP in HTML Pages?


PHP in HTML Pages?

Reply
  #11 (permalink)  
Old 01-04-06, 01:25 PM
johndapunk johndapunk is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
It shouldnt be nessesary for you to change all of your code to php only because your change your file extension to .php. Let me show you my header.php that has minimal php in it, but also has functioning html elements in it.
Code:
<?php
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
John Vollrath's Personal Website
Developed by: John Vollrath
12-30-05
Header Page
*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$user = 'John Vollrath';
?>
<html>
<head>
<title><?php echo ($user) ?> Personal Page</title>
<LINK REL=STYLESHEET TYPE="text/css" HREF="stylesheet.css">
</head>
<body bgcolor="363636">
<!-- Logo starts here -->
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1" width="100%" height="108"><tr><td colspan="2">
<center><img src="http://img523.imageshack.us/img523/9617/logo8bs.jpg"></center>
</td></tr>
<!-- Logo ends here -->
<!-- Navabar Starts Here -->

<?php
include ("nava.html")
?>

<!--NavaBar Ends here -->
<!-- Miscellaneous Begins Here -->

<?php
include ("miscellaneous.html")
?>

<!-- Miscellaneous Ends Here -->
<td valign="top">
<center>
	<table width="800" class='bodytable'>
<tr><td width="700" class='cap'><center><?php echo ($user) ?>
</center></td></tr>
<tr><td>
</body>

</html>
As you can see, you don't need to change everything to php code, at least i didnt have to.
Reply With Quote
  #12 (permalink)  
Old 01-04-06, 01:40 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Quote:
Originally Posted by YourPHPPro
The easiest way would be to edit the configuration file for the webserver (example is for apache) and add:

Quote:
AddType application/x-httpd-php .php .phtml .php4 .php3 .html .htm
The second easiest way would be to edit the directory configuration file (.htaccess for apache) and add:

Quote:
AddType application/x-httpd-php .php .phtml .php4 .php3 .html .htm
As YourPHPPro said, create a .htaccess file and use the following code:

Code:
AddType application/x-httpd-php .html .htm
Now all .html/.htm files will be paraphrased as php. Is as simple as that.
Reply With Quote
  #13 (permalink)  
Old 01-04-06, 04:49 PM
ZeoFateX ZeoFateX is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Earth
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Wow I posted this back in 2003, but I had e-mail response on this. Thanks for the info though! I'm not too sure how you dug this post up from the depths of the forum o.O
Reply With Quote
  #14 (permalink)  
Old 01-04-06, 05:50 PM
knine143 knine143 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
If a file extension is .php, then you can have php in it as well as any html....
Reply With Quote
  #15 (permalink)  
Old 01-04-06, 05:53 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by knine143
If a file extension is .php, then you can have php in it as well as any html....
But it isn't dependent on the extension. You can easily put php code in a file and have its extension as .xxx as long as the webserver knows to send .xxx files through PHP first...

This must get the record for the longest 'dead' topic pulled back to life...
Reply With Quote
  #16 (permalink)  
Old 01-04-06, 05:55 PM
knine143 knine143 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
True true. But for people like me that are hosting on a remote server and can't change the configuration, that doesn't work.

And yes, definitely sets the record
Reply With Quote
  #17 (permalink)  
Old 01-04-06, 06:06 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Yeah wow, I didn't realize that this thread is a year old. johndapunk really did some diging.
Reply With Quote
  #18 (permalink)  
Old 01-04-06, 06:10 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dead-poetic
Yeah wow, I didn't realize that this thread is a year old. johndapunk really did some diging.
Closer to two years and three months.. give or take a few days...
Reply With Quote
  #19 (permalink)  
Old 01-04-06, 06:28 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Your right, what I meant to say was that it was older than a year, just a little typo.
Reply With Quote
  #20 (permalink)  
Old 01-04-06, 06:42 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by ZeoFateX
Is it at all possible to use PHP in a .html page. My server uses PHP,MySQL, etc but I built one website completely in HTML. I want to use a small php script inside the HTML page without having to convert the whole page to PHP. Is this possible (even with javascript or some other language usable by HTML?). Or if someone can help me out with a script that calls HTML FORMATTED text from a text file located on the server.
Yes, you can, and here's the easy way:

1) Use an .htaccess file with this line in it:

AddType application/x-httpd-php .php .htm .html

That's it, you're done. All .html pages will be processed as if they had the extension '.php'.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 08:03 PM
PHP script to parse HTML Skeleton Man Script Requests 2 10-05-03 08:41 PM
What PHP Scripts Should I Be Using? HELP HELP!! pelican PHP 2 08-20-03 02:06 AM
Include asp-generated html in php rancor PHP 2 08-05-03 03:03 AM


All times are GMT -5. The time now is 07:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.