Results 1 to 2 of 2

Thread: what is it doing

  1. #1

    Thread Starter
    Hyperactive Member notquitehere188's Avatar
    Join Date
    Dec 2004
    Posts
    403

    what is it doing

    im trying to learn php and i came across this sample code
    Code:
    <html>
    <body>
    
    <?php
    $d=date("D");
    if ($d=="Fri")
    echo "Have a nice weekend!"; 
    else
    echo "Have a nice day!"; 
    ?>
    
    </body>
    </html>
    what is the line "$d=date("D");" doing and why is it not setting a value of fri or something
    It's not just Good, It's Good enough!



    Spelling Eludes Me

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: what is it doing

    That is a very poor example. I would actually re-write it to the following:
    PHP Code:
    <html>
        <head>
        </head>
        <body>
            <p>
    <?php

    $d
    =date("D");

    if (
    $d=="Fri") {
        echo (
    "Have a nice weekend!"); 
    } else {
        echo 
    "Have a nice day!"
    }
    ?>
            </p>
        </body>
    </html>
    All I've done is indented the code and made sure the HTML was correct but these are important habbits to get into if you are learning.

    The $d=date("D"); line assigns thee return value from calling PHP's date() function to the variable $d. The string "D" is the format in which the date can be return and on PHP.Net it explains:
    D A textual representation of a day, three letters Mon through Sun
    Therefore it will return either Mon,Tue,Wed,Thu,Fri,Sat or Sun depending on the day.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width