PHP into HTML

beastmodeenabled86

New Member
Messages
9
Reaction score
0
Points
0
Hey Guys,

I am a bit of a novice at coding and i have a php script saved as "test.php" and i want it to be in the html code. How would i go about doing this without just copying the php code into the html.

<p><b>Current Song:</b> <?php include("test.php");?> </p> </div>

I am doing this but now nothing appears, any help?
 
Last edited:

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Change the filename extension of the html page to php. EG: somepage.html to somepage.php
then the include command should work inside the page.
 

Quozzo

New Member
Messages
11
Reaction score
0
Points
0
Make sure the HTML and the test.php file are in the same directory and the test.php file has the starting <?php tag and end ?> tag, not like hosting JS.
 

wilron818

New Member
Messages
13
Reaction score
0
Points
0
You can't include php file into an html file. if you want to have an html file extension in your url, like "www.yourdomain.com/yourfile.html", you must use .htaccess...
 

arradia

New Member
Messages
5
Reaction score
0
Points
0
just to clarify - php doesn't get executed unless it's passed through the php parser (a program sitting on the server) and it won't get passed to the parser unless the server knows it's a php file - ie it ends in .php (or phtml or php5). You can rig .htaccess to shove everything through the parser but that's a complete waste of bandwidth and will slow your whole server down.

test.php only needs <?php ?> if it contains code - if it's straight text then it won't need them. in fact you can speed things up by not pushing it through the parser; <?php include("test.txt") ?> will work for straight text.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
test.php only needs <?php ?> if it contains code - if it's straight text then it won't need them. in fact you can speed things up by not pushing it through the parser; <?php include("test.txt") ?> will work for straight text.

That still puts everything through the parser and slows things down because it has to grab text.txt .
 

arradia

New Member
Messages
5
Reaction score
0
Points
0
It won't need to pull test.txt through it so it won't stop to parse it. Obviously it will need to execute the calling script or the include will never happen.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
It won't need to pull test.txt through it so it won't stop to parse it. Obviously it will need to execute the calling script or the include will never happen.

Any file you include is passed through the parser.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
readfile will output the contents of a file without processing it as PHP. My tests indicate readfile is about twice as fast as include on a file with no PHP. It's only about 0.0241 ms/KiB for include, compared to 0.0123 ms/KiB for readfile. In short, the penalty for using include over readfile is so small as to be unnoticeable, but there's no advantage to include.

It's not bandwidth that's wasted by having PHP process files containing no PHP code (as the output is the same either way), it's processor cycles.
 

telugutopadmin

New Member
Messages
40
Reaction score
0
Points
0
hi how to convert and how can we get .htaccess file for the html site to php site please help me i want to convert my site to .php please thank U
 
Top