help me with PHP?

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by dieutran, Sep 16, 2014.

  1. dieutran

    dieutran New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi guys,
    I have a problem with php.
    In my public_html directory, if I have a file named "index.php": <?php echo "something"; ?>, it works perfectly.
    But in the same directory, if the file is "index.html":
    <html>
    <head>
    <title> hello </title>
    </head>
    <body>

    <?php echo "something"; ?>
    </body>
    </html>
    it doesn't work. it displays nothing.
    Can someone tell me why? Thanks>:):(:)
     
  2. leafypiggy

    leafypiggy Manager of Pens and Office Supplies Staff Member

    Messages:
    3,819
    Likes Received:
    163
    Trophy Points:
    63
    .html files are not parsed by the server, they're just HTML.
     
  3. nkranx10

    nkranx10 Member

    Messages:
    62
    Likes Received:
    2
    Trophy Points:
    8
    he means the PHP bit inside the .html file will not be parsed .Files called .php tell the server there is PHP stuff to parse on the server and throw back into a browser readable form.
     
  4. leafypiggy

    leafypiggy Manager of Pens and Office Supplies Staff Member

    Messages:
    3,819
    Likes Received:
    163
    Trophy Points:
    63
    Thank you for the clarification. My response was rushed. :)
     
  5. dieutran

    dieutran New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    thanks.
    very clearly :D
     
  6. gfxice

    gfxice New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    You should learn this from w3school already ?
     
  7. nkranx10

    nkranx10 Member

    Messages:
    62
    Likes Received:
    2
    Trophy Points:
    8
    the best way of learning is just to try , make mistakes post here, google and keep on going .Preferably you should have a localhost web development set up to play with such as xampp on linux or wamp. If you are not yet doing this google apachefriends and xampp/wamp site should come up
     
  8. caftpx10

    caftpx10 Well-Known Member

    Messages:
    1,502
    Likes Received:
    110
    Trophy Points:
    63
    The interesting thing is that the browser hides the PHP when it is in a .html or any similar file.
     
  9. uraceele

    uraceele Member

    Messages:
    54
    Likes Received:
    8
    Trophy Points:
    8
    It shouldn't surprise you. As another person said the file extension determines how the file is going to be rendered...
     
  10. caftpx10

    caftpx10 Well-Known Member

    Messages:
    1,502
    Likes Received:
    110
    Trophy Points:
    63
    I guess HTML renders it as a whole tag.
     
  11. caftpx10

    caftpx10 Well-Known Member

    Messages:
    1,502
    Likes Received:
    110
    Trophy Points:
    63
    Now that I think about it, no I shouldn't.
    It gets rendered as a HTML tag.
     
  12. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    It's actually an SGML (Standard Generalized Markup Language) processing tag, and would live outside of the HTML document (like "HTML" comments and the doctype declaration, which are also SGML commands). Browsers can read some SGML; that's what they use to determine which markup language and which dialect of that language the document is written in (they assume HTML 3.2-ish if nothing is specified unless there is a tag that wouldn't be allowed in HTML 3.2 or 4.01 Transitional). IE uses SGML for some browser-specific processing instructions (often referred to incorrectly as "conditional comments") based mostly upon the browser version. Since those instructions are in SGML and are defined in an IE-specific document type definition, other browsers will ignore them as if they were comments.
     
    • Informative Informative x 1
  13. bradleyx

    bradleyx Member

    Messages:
    108
    Likes Received:
    1
    Trophy Points:
    18
    Code:
    <html>
    <head>
    <title> hello </title>
    </head>
    <body>
    <?php echo "Something"; ?>
    </body></html>
    
    change the .html to .php it will work then. .html will not process php code it will just show it or none.

    php is different from .html files.
     
  14. bdistler

    bdistler Well-Known Member Prime Account

    Messages:
    3,534
    Likes Received:
    195
    Trophy Points:
    63
    you can use code within a [ .htaccess ] file to tell the server - to render (scan) all HTML files as PHP files
     
  15. bradleyx

    bradleyx Member

    Messages:
    108
    Likes Received:
    1
    Trophy Points:
    18
    yes you are right. but that can process a security risk tho. its easier to hack files that way in my opinion.
     
  16. ttbx10ho

    ttbx10ho Member

    Messages:
    62
    Likes Received:
    5
    Trophy Points:
    8
    try Server Side Include with a shtml extension
    Code:
    <!--#include file="footer.html" --> 
    .
    This can be fun.
     

Share This Page