+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: PHP into HTML

  1. #1
    beastmodeenabled86 is offline x10Hosting Member beastmodeenabled86 is an unknown quantity at this point
    Join Date
    Jul 2011
    Posts
    9

    PHP into HTML

    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 by beastmodeenabled86; 07-06-2011 at 12:58 PM.

  2. #2
    cybrax's Avatar
    cybrax is offline x10 Elder cybrax is on a distinguished road
    Join Date
    Aug 2009
    Location
    UK
    Posts
    699

    Re: PHP into HTML

    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.
    The code must flow.
    Project 157: Latest UK Jobs direct to your mobile phone
    New Domain under construction: Lovelogic.net
    home for some new projects that we can't keep here ;)


  3. #3
    Quozzo is offline x10Hosting Member Quozzo is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: PHP into HTML

    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.

  4. #4
    wilron818 is offline x10Hosting Member wilron818 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    13

    Re: PHP into HTML

    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...

  5. #5
    beastmodeenabled86 is offline x10Hosting Member beastmodeenabled86 is an unknown quantity at this point
    Join Date
    Jul 2011
    Posts
    9

    Re: PHP into HTML

    Quote Originally Posted by cybrax View Post
    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.
    Thank You! Much appreciated.

  6. #6
    arradia is offline x10Hosting Member arradia is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    5

    Re: PHP into HTML

    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.

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP into HTML

    Quote Originally Posted by arradia View Post


    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 .
    Nothing is always absolutely so.

  8. #8
    arradia is offline x10Hosting Member arradia is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    5

    Re: PHP into HTML

    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.

  9. #9
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP into HTML

    Quote Originally Posted by arradia View Post
    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.
    Nothing is always absolutely so.

  10. #10
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP into HTML

    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.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 06-24-2011, 09:01 PM
  2. Replies: 9
    Last Post: 06-25-2010, 12:47 AM
  3. Replies: 1
    Last Post: 05-08-2008, 04:40 PM
  4. HTML or PHP???
    By trebor2510 in forum Computers & Technology
    Replies: 25
    Last Post: 12-24-2007, 10:08 PM
  5. HTML ONLY or a CMS with NO EDITABLE HTML?
    By SykaX in forum Crossfire
    Replies: 7
    Last Post: 11-29-2007, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers