+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Famous Hello World

  1. #1
    Khaotic is offline Learning Programmer
    Join Date
    Apr 2009
    Location
    Brandon, Mississippi, United States
    Posts
    62
    Rep Power
    12

    Cool Famous Hello World

    Yes, I know, easy code. Well, this is just to show some users how easy php is. Without further ado, the code itself:

    Code:
    <?php
    
    echo "Hello World!";
    
    ?>
    Explanation:
    <?php - tells the file that this is php coding. *.php files can contain html by default. The php extention says this is where I want the php to go. You can have multiple php coding in a file.

    echo "Hello World!"; - Prints "Hello World" to the screen(without the quotes). When you want to output text or anything that is not a variable or such, wrap it in quotes so php doesnt interpret it as such.

    ?> - Closes the php code.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Famous Hello World

    Echo is actually a function in PHP you can use it like:
    Code:
    echo("Hello World!"); 
    I think that is the proper way of doing it - I suppose deep down everything is made up of functions and variables - then computer language - 0's and 1's - somewhat depressing...

  4. #3
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: Famous Hello World

    Both ways work thou.

    @kahotic : You have to crawl before you walk. I am sure some one who has never used PHP before will find it helpful

  5. #4
    Jordan Guest

    Re: Famous Hello World

    Actually, it isn't a function:

    echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it
    PHP: echo - Manual

  6. #5
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Famous Hello World

    Well then - I'm an idiot.

    You can still use it like a function however =)

  7. #6
    Jordan Guest

    Re: Famous Hello World

    lol, I wouldn't go that far. You showed an alternative method to use it which some people may prefer (like yourself).

  8. #7
    Khaotic is offline Learning Programmer
    Join Date
    Apr 2009
    Location
    Brandon, Mississippi, United States
    Posts
    62
    Rep Power
    12

    Re: Famous Hello World

    Yeh, I remember when I was first learning php(couple years back when I was 11 or so), it said that using parentheses is the correct way of using it. I find it better to just use 'echo' as a keyword rather than "function".

  9. #8
    Jordan Guest

    Re: Famous Hello World

    I've never read that parentheses is the correct way to use it. In fact, in some situations, you can't use parentheses (IE: You are passing multiple parameters to it).

  10. #9
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Famous Hello World

    Im pretty sure you can pass multiple params to it if you use the ():

    Code:
    <?PHP
    $var1 
    ="hello";
    $var2 "world";
    echo(
    "hello ".$var2);
    echo(
    $var1." ".$var2);
    echo(
    "hello"." "."world");
    ?>
    I am pretty sure all those would work just like regular functions. (but its not a function lols)

  11. #10
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Famous Hello World

    Technically, wouldn't the concatenation happen first, resulting in a single parameter?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Famous programs created in different programming languages
    By An Alien in forum General Programming
    Replies: 3
    Last Post: 10-27-2011, 09:32 PM
  2. Replies: 9
    Last Post: 01-14-2011, 12:59 PM
  3. Hello...world --sorry couldn't help it
    By debtboy in forum Introductions
    Replies: 11
    Last Post: 09-04-2009, 03:44 PM
  4. Hello world
    By Vswe in forum Introductions
    Replies: 8
    Last Post: 05-02-2009, 03:11 PM
  5. Hello World!
    By ThemePark in forum Introductions
    Replies: 7
    Last Post: 11-07-2008, 05:09 AM

Tags for this Thread

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