Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: How do I insert PHP into HTML page?

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Huh?

    You can add PHP to html all you want. Just, as you said, put it in PHP tags...
    S/he's right... technically you're adding HTML to PHP, since the whole thing is sent through the PHP parser.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's a page of text.

    1+2 gives the same results as 2+1, unrelated to which is done first or which is being added to the other.

    <html></html> --> <html><?php echo "<body>"; ?></html>
    No?

    It's just an issue of semantics, though, unrelated to the code anyway.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <html></html> --> <html><?php echo "<body>"; ?></html>
    No?
    Not necessarily. In fact, I'd say even the <html></html> is technically PHP if it's being sent through the parser; the fact that the PHP parser decides to output this part of the code verbatim is irrelevant.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You have html page. Then you rename that page whatever.php. And that's all PHP code?
    Whether or not you want to argue that, it doesn't really hold up in any practical situation. If you're using PHP, you still need to know html, right?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ah, but what about other file types PHP can send out? CSS, JavaScript, images...they all run through the PHP parser and gives the browser something IT can work with...

    I'm with Twey, here. If the file is a PHP file, everything in it is technically PHP.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you're using PHP, you still need to know html, right?
    Only if you want to output HTML. Not necessarily even then, actually, since there are DOM builders and things that allow one to generate an HTML document without knowing HTML, in much the same way that GD allows one to generate a GIF image without knowing the GIF format.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    So... Javascript and CSS are also PHP?
    JPGs are as well, if they are served through PHP?


    This argument could go on forever, just depending on how you want to look at it.

    Is the word "Pi&#241;ata" Spanish or English when used in English, such as "I just hit a pi&#241;ata."?
    It's Spanish. But it's used in English. It's also an acceptable word in English, without a substitute. So it must be English. But it's Spanish. It's PHP. It's HTML. It's.... a pi&#241;ata.

    It's worth knowing that the text is sent through the parser, but only to the extent that you know which portions are actually parsed as PHP and which are not (and what happens to those sections that are). Aside from that, all that matters is that you use the same html as you would have in the first place. Certainly nothing to do with PHP.

    On top of that, there's a weird generalization being made by this. PHP code and that-which-is-parsed-as-PHP are two separate things.

    There is HTML markup and PHP code on a page, and both are passed through the PHP parser. Each is still its original form, yet they are, yes, passed through the parser. In the same sense, there could be PHP code and HTML markup on a page which is not (either by accident, or perhaps as an example of PHP coding) parsed as PHP at any point. Does that mean that the PHP code is HTML? Sure, it's shown as HTML, but the code itself is still PHP.

    If you dump water on a sponge, then it's a sponge... it's intended use. But if you dump water on a rock, that doesn't magically make it a sponge. Sure, it had water dumped on it, so it became a thing-that-has-water-dumped-on-it, but it's still not a sponge...

    Considering anything on the page as PHP is ridiculous and vague as things start to lose their meanings. If you were to accidentally parse ASP as PHP, then you're claiming that it is then PHP?

    HTML and PHP can exist on the same page, and the difference is when they are interpreted. The PHP parser takes all PHP, and transforms it, but not the HTML, into a final state, which is no longer PHP, but plain text, usually HTML. This is then sent on to the browser, as HTML. The browser then interprets the HTML and displays it.



    *Note that in some cases, HTML in this post could/should be expanded to DHTML in general, though it's not too important for the point.



    EDIT: In response to your latest post, Twey:
    Sure. You can use PHP for different output, but we're talking about a page that has mixed PHP and HTML at the moment. That's irrelevant (and the same argument could occur over PHP generating anything, such as MySQL data).
    As for templates/functions in use by PHP to generate html, that may be true, but, again, this IS PHP code, rather than plain HTML on the page. I'm not talking about a page that starts with <?php and ends with ?>, with no breaks to the parsed segment, but a page that has some HTML and some PHP included as well.


    EDIT 2: Perspective:
    I think the main issue here is how you are looking at the situation.
    As the server, it is certainly PHP, and must be parsed as such. The act of not parsing specific segments is part of parsing. So, yes, in a way the HTML is treated as PHP.
    However, as the programmer/coder, they are very different things, with the HTML written differently than the PHP.
    Perhaps this is partly due to the fact that you're more in touch with how the server actually processes than I am, to a crazy degree (not to say bad... it's useful, and amusing), so you're looking at it from this angle.
    Last edited by djr33; 07-22-2007 at 07:28 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #18
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is the word "Pi&#241;ata" Spanish or English when used in English, such as "I just hit a pi&#241;ata."?
    It's Spanish. But it's used in English. It's also an acceptable word in English, without a substitute. So it must be English. But it's Spanish. It's PHP. It's HTML. It's.... a pi&#241;ata.
    It's Spanish... the techical term for it is a "loanword." Language definitions are unclear, though... the boundary between a loanword and a native word is as the boundaries between two languages themselves.
    On top of that, there's a weird generalization being made by this. PHP code and that-which-is-parsed-as-PHP are two separate things.
    Not really. They're both just binary data, in the end, like languages are just sounds or marks on paper.
    There is HTML markup and PHP code on a page, and both are passed through the PHP parser. Each is still its original form, yet they are, yes, passed through the parser. In the same sense, there could be PHP code and HTML markup on a page which is not (either by accident, or perhaps as an example of PHP coding) parsed as PHP at any point. Does that mean that the PHP code is HTML? Sure, it's shown as HTML, but the code itself is still PHP.
    No, it's PHP, since it was interpreted by the PHP parser.
    If you dump water on a sponge, then it's a sponge... it's intended use. But if you dump water on a rock, that doesn't magically make it a sponge. Sure, it had water dumped on it, so it became a thing-that-has-water-dumped-on-it, but it's still not a sponge...
    If it was intended to be used as a sponge, then yes, it's a very poor sponge
    Considering anything on the page as PHP is ridiculous and vague as things start to lose their meanings. If you were to accidentally parse ASP as PHP, then you're claiming that it is then PHP?
    Invalid PHP, yes.
    HTML and PHP can exist on the same page, and the difference is when they are interpreted. The PHP parser takes all PHP, and transforms it, but not the HTML, into a final state, which is no longer PHP, but plain text, usually HTML. This is then sent on to the browser, as HTML. The browser then interprets the HTML and displays it.
    I'd be inclined to say that the HTML is also transformed -- just into the same HTML that it was in the first place. It's kind of like ROT26 encryption. Movement and transformation are the same thing for electronic and neural data, after all: the electrons of one moment aren't the exact same electrons of the moment before.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #19
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Then how do you define the chunks that I say are HTML as different from the chunks that I say are PHP? Surely there is a difference, and one that can easily be seen. "HTML parsed as PHP" and "PHP parsed as PHP"? That still means one is PHP and the other is HTML. Perhaps "HTML-like PHP" and "PHP-like PHP"?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #20
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Heh, ah, you haven't been reading my posts properly Since the only way to tell one from the other is by the way they're interpreted, the interpreter defines which is which. The PHP interpreter only sees PHP (thus, it's a PHP interpreter) because it's a machine. Humans are capable of drawing a line between HTML and PHP based on the semantics and patterns of each -- thus, to a human examining the code, there is indeed a difference between the "HTML" portions and the "PHP" portions, and a string such as:
    Code:
    print "<html>";
    is both PHP and HTML, depending on how the examiner is seeing it: if the examiner notes it only as a string that the PHP will output, then it's PHP; if the examiner attempts to work out the final HTML document that the PHP will generate, for example, and takes it in context with the rest of the HTML document, it's HTML.

    However, it's silly to attempt to define such things on so ambiguous a measure, so it's wisest to take it at the parser's value (the parser is, after all, the last observer to interpret the code) and say that it's all PHP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •