Coffeehouse Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Question on PHP.

Back to Forum: Coffeehouse
  • User profile image
    Steve411

     I'v decided to take an approach on PHP 5 development.. So far it's great.. The book is amazing, it gives a lot of details and explains each segment clearly.. So after reading a few chapters I decided to give it a go using the simple statements.. Please if you can correct the code i'v written here.. God Bless, Steve

    <html>
     <head>
      <title>$page_title</title>
     </head>
    <body>

     //Main PHP Section of the code

    <?php
       $page_title = 'PHP Prints out my name. Smiley';
       $stevens_name = 'Stevan Veselinovic';
       $page_purpose = 'PHP Prints out my name. Smiley';
       $day = '11';
       $mark_day = '\'st';
       $month = 'November';
       $year = '1989';
       $profession = 'PHP Student';
    if ($day != 1) {
       $mark_day = 'st';
    }
     else {
       if ($day = 2) {
          $mark_day = 'nd';
     }
    }
     else {
      if ($day >= 4,5,6 + 1) {
         $mark_day = 'th';
     }
    }
      else {
       if ($day = 3) {
          $mark_day = 'rd';
     }
    }
    ?>
      // End the PHP Section of the code
      //Show the page purpose

    <?php
      print '$page_purpose';
    ?>
    < /br>
    < /br>
    <table id="tblDisplayText">
     <tr>
      <td>
    <?php
        print "$stevens_name" was born in '{$day . $mark_day}d of $month in the year: $year';
        print /n;
        print "$stevens_name . \'s" profession is '$profession';
    ?>
      </td>
     </tr>
    </table>
     </body>
    </html>

  • User profile image
    Shining Arcanine

    Have you read the PHP Manual?

  • User profile image
    Steve411

    Shining Arcanine wrote:
    Have you read the PHP Manual?

     No, i read the "Learning PHP 5" book from O'Reilly Media.
     http://www.oreillynet.com/cs/catalog/view/au/985?x-t=book.view

  • User profile image
    Jeremy W

    You're gonna want to use echo for displaying the results of variables Smiley

  • User profile image
    UdoSchroeter

    What's this??? Man, you need to start with the basics! Just a few points...

    <title>$page_title</title>
    This isn't going to work. You need to tell the interpreter which sections are code and which are HTML. So you'll need to use a PI for that:
    <title><?php print($page_title); ?></title>

    I guess I don't need to tell you that this code's indentation sucks, right?

    Also, don't do an else after an else. That's a nono in every programming language I know. "if-else-else", not going to work.

    print "$stevens_name" was born in '{$day . $mark_day}d of $month in the year: $year';
    print /n;
    print "$stevens_name . \'s" profession is '$profession';
    The meaning of these horrible constructs escapes me. Especially the last one. Use either ' or " and then stick to it. Unless you really know what you're doing. But this is so totally screwed up, I don't know what to say! If you're a programming newbie, you need to learn what a variable is, what a string is, and how special characters in strings are escaped properly. You need to learn about operators, too.

    print '$page_purpose';
    If you are going to use ' to delimit text, know that the interpreter takes this to be a literal string, so you get literally $page_purpose not its content. You can do
    print "$page_purpose";
    or
    print $page_purpose;
    or, more beautifully
    print($page_purpose);
    On a side note, this coding style is what's given PHP its bad reputation. You know, you *can* write readable, clean code with it. The problem is just that you don't actually *have* to.

    <>?>
      // End the PHP Section of the code
      //Show the page purpose
    <?php
    Don't do this, unless you want to see your comments on the page in the browser window.

    Semantically, your code won't do much either. I guess you want to hook on "-st", "-nd", "-th", and "-rd" to a number but for this to work properly you will need to look at the last character of the string.

    I know, it sounds arrogant, but I have to ask. Did you even think for a second when you wrote this, or are you just totally new to web programming in general? Since this is C9, it might also be an attempt to somehow discredit PHP, because it's so "ugly" and "difficult" ? Again, I'm really sorry if you feel flamed. I apologize if you're a web-newcomer. It just looks so strange...

  • User profile image
    Shining Arcanine

    Jeremy W. wrote:
    You're gonna want to use echo for displaying the results of variables Smiley


    The only difference between echo and print is that print is an alias of echo therefore making echo slightly but unnoticability faster.

  • User profile image
    Jeremy W

    I know, which is why it confused me that you'd use print, as it's all very oldschool. I was also stating the obvious becuase you weren't using anything in the <title> section of your code.

  • User profile image
    Steve411

    Thanks guys. Figured i'd be wrong. Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.