home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] html/php 'Hello World'


On 17-Apr-07, at 7:08 PM, William Case wrote:

Hi;

I got the 'Hello World' practice file working then began playing with
it. My problem is getting the commenting out to work. I have obviously
missed something.

Here is the little program:
<html>
  <head>
    <title>'PHP Test'</title>
  </head>

  <body>

  <?php echo '<p>Hello World</p>' ?>

<!--
  <?php
  if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
    ?>   <!-- missing -->
    <h3>'strpos()must have returned non-false'</h3>
    <p>'You are using Internet Explorer'</p>

  <?php
   } else {
  ?>

    <h3>'strpos() must have returned false'</h3>
  <p>'You are not using Internet Explorer.'</p>

  <?php
   }
  ?>
-->

  </body>

</html>


  <?php /*phpinfo();*/ ?>

The HTML manual told me to use <!-- and --> to make comments. The body
outside of the comment tags worked on my browser as it should.  The
stuff in between <!-- ... --> is things that I am trying out (playing
with). I wanted to comment out the stuff in order to find the error
causing the blank screen that I am getting on my browser.  My main
concern and to which I don't seem to be able to find an answer is how to
comment out properly.

I believe that the HTML comments are interpreted by the browser. The PHP inside the comments will still be executed on the server.


Similarly, <?php /*phpinfo();*/ ?> at the bottom is something I used to
experiment with commenting out in PHP.  Originally I had  /*
<?php /*phpinfo(); ?> */ placed where it is now -- outside of HTML or
any other tags yet the string showed up on my browser screen. That
doesn't make sense to me.  So, why?

In the original line, the comment delimiter is outside the php tags. You need to watch that the HTML and php are well separated.

... Glenn

--
Glenn Henshaw              Ottawa, Canada
Email: thraxisp4 [ at ] mac [ dot ] com



references