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


PHP in HTML Pages?

Reply
  #1 (permalink)  
Old 10-20-03, 05:03 PM
ZeoFateX ZeoFateX is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Earth
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question PHP in HTML Pages?

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.

Thanks,

Zeo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-20-03, 06:49 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Simpler than you think. Just change the extention on your page from .html to .shtml

.shtml will allow php scripts to be included, and displays the same as the html version.

Thats it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-21-03, 03:44 PM
ZeoFateX ZeoFateX is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Earth
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mdhall
Simpler than you think. Just change the extention on your page from .html to .shtml

.shtml will allow php scripts to be included, and displays the same as the html version.

Thats it.
Doesn't seem to be working.

<?php
function ReadFromFile () {
$TheFile = "scroller.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
$Data = file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode("\t", $Data[$n]);
print ("$GetLine[0]<BR> \n$GetLine[1]<P>\n");
}
fclose ($Open);
print ("<HR><P>\n");
} else {
print ("Unable to read from scroller.txt!<BR>\n");
}
}
ReadFromFile()
?>

On the page it outputs:

\n$GetLine[1]

\n"); } fclose($Open);
print ("

\n"); } else
{ print
("Unable to read from scroller.txt!\n"); }
}
ReadFromFile()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-21-03, 03:51 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Did you try it as a virtual include?

<!--#include virtual="foldername/scriptname.php-->

For example, if I'm adding a "visitors online" php script names "visitors.php" to an shtml page, and the script is in a folder called "online", I would use this...

<!--#include virtual="online/visitors.php"-->

See if that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-21-03, 06:33 PM
cl0 cl0 is offline
New Member
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
1. add a semicolon after you call the function, so the line should read
ReadFromFile();

2. your server doesn't seem to be configured to use the .shtml-extension. instead, use ".php" for your php-scripts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-21-03, 08:01 PM
ZeoFateX ZeoFateX is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Earth
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
for the #include, inside the php script or inside the header? cl0 the whole point is that I didn't have to convert my website to php, I have php on my server, but this is a small script... for something that I don't even *really* need.

Edit:

Nice, I fooled around with the #include thing for a bit and figured it out. It works like a charm. Thanks ^.^.

Last edited by ZeoFateX; 10-21-03 at 08:08 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-21-03, 08:16 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
I should have specified to put the <--include--> into your shtml page where you want it to display...not the header.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-22-03, 10:42 AM
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 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.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 11-14-03, 11:26 PM
php4 php4 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

replace your html files extensions to php.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 11-15-03, 07:08 AM
ZeoFateX ZeoFateX is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Earth
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
That's not what I was looking to do. I already have this figured out thanks to mdhall. What I was trying to do was just put a small php script inside my html page without having to change the whole page to php. Thanks for the reply though.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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 03:22 AM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 09:03 PM
PHP script to parse HTML Skeleton Man Script Requests 2 10-05-03 09:41 PM
What PHP Scripts Should I Be Using? HELP HELP!! pelican PHP 2 08-20-03 03:06 AM
Include asp-generated html in php rancor PHP 2 08-05-03 04:03 AM


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