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

Thread: PHP Tutorial

  1. #1
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    PHP Tutorial

    Well I thought in order to test my skills I would write a tutorial on PHP! It is only basic, so to help out others etc.

    PHP Code:
    <?php
    echo ('Hello World');
    ?>
    Result: Hello World is written to the page!

    PHP Code:
    <?php
    $text 
    "Hello World!";

    echo (
    $text);
    ?>
    Result is still Hello World on the page, however the text is stored in the variable $text

    PHP Code:

    <?php

    $text
    [1] = "Hello World!";
    $text[2] = "Hello Monkey!";

    echo (
    $text[1]);
    echo (
    $text[2]);


    ?>

    Result is Hello World! Hello Monkey, written to the page. The variable is the same however the instances of them are different. Note the [1] and [2] next to them.

    Hope you find it simple and easy to understand.

    Author: Zenax
    Regards,
    Zenax

  2. #2
    Derek is offline Community Support Force Derek is a splendid one to beholdDerek is a splendid one to behold
    Join Date
    May 2005
    Location
    cossacks
    Posts
    6,354

    Re: PHP Tutorial

    Thanks for the tut helped me ALOT

  3. #3
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP Tutorial

    You have this:

    PHP Code:
     <?php

    $text
    [1] = "Hello World!";
    $text[2] = "Hello Monkey!";

    echo (
    $text[1]);
    echo (
    $text[2]);


    ?>
    This should also work, not tested.


    PHP Code:
    <?php

    // $text is an array!
    $text[1] = "Hello World!";
    $text[2] = "Hello Monkey!";

    foreach (
    $text as $echo) {

    echo 
    $echo;

    }

    ?>
    Functions used: foreach(), echo()
    Last edited by Brandon; 04-22-2007 at 12:57 PM.
    Thanks,
    Brandon Long

  4. #4
    Cubeform is offline x10 Lieutenant Cubeform is an unknown quantity at this point
    Join Date
    Aug 2006
    Location
    127.0.0.1
    Posts
    339

    Re: PHP Tutorial

    Or, for the array, you could do this:

    PHP Code:
    <?php
      $text
    = array("Hello World!","Hello Monkey!");
      
    // Note that the first item in the array would be $text[0]
    ?>
    Or this:

    PHP Code:
    <?php
      $text
    = array(=> "Hello World!"=> "Hello Monkey!");
    ?>
    Or this:
    PHP Code:
    <?php
      $text
    = array("world" => "Hello World!""monkey" => "Hello Monkey!");
    ?>
    All three achieve the same result. All are tested and all work.
    CUBEFORM
    XHTML | CSS | PHP | JavaScript
    THIS WEEK


  5. #5
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP Tutorial

    Or if you want to be advanced you can do this.

    PHP Code:
    <?php

    $words 
    "Hello World!,Hello Monkey!";

    $text explode(",",$words);

    ?>
    Of course, untested

    Functions used: explode()
    Last edited by Brandon; 04-22-2007 at 02:43 PM.
    Thanks,
    Brandon Long

  6. #6
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    Re: PHP Tutorial

    Thank you guys! This was meant to be simple and easy for beginners and now I have fount even more ways of achieving this!

    im just picking things up as I go along, like i got the $text[1] thing from a login script t2t2 wrote for me!
    Regards,
    Zenax

  7. #7
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP Tutorial

    Quote Originally Posted by Zenax View Post
    Thank you guys! This was meant to be simple and easy for beginners and now I have fount even more ways of achieving this!

    im just picking things up as I go along, like i got the $text[1] thing from a login script t2t2 wrote for me!
    Indeed you did I bet.

    You can also do: $text['brandonrules']

    that works too, just edit the 'brandonrules' to other text.
    Last edited by Brandon; 04-22-2007 at 06:27 PM.
    Thanks,
    Brandon Long

  8. #8
    t2t2t's Avatar
    t2t2t is offline x10 Elder t2t2t is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    Europe, Estonia
    Posts
    690

    Re: PHP Tutorial

    PHP Code:
    <?
    $text 
    'Hello';
    if (
    $text 'Hello') print $text .' World!'// Hello World!
    if ($text) print "$text World!"// Hello World!
    print '$text World'// $text World
    // (in single-quote, variables don't get changed, with double-quotes, PHP will ALWAYS look for a variable,
    // so its most efficient to use first print)
    print 'I said Hello to you at 'date(r) .'!';
    ?>
    Last edited by t2t2t; 04-22-2007 at 11:37 PM.
    This post has been marked spam 52 times.


  9. #9
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    Re: PHP Tutorial

    Thanks again guys!

    I wrote this:
    PHP Code:
    <?php

    class hello
    {

        function 
    world()
        {
        
            echo (
    'Hello World!');
            
        }
        
        function 
    monkey()
        {
        
            echo(
    'Hello Monkey!');
            
        }
        
    }

    $helloworld = new hello;
    echo 
    $helloworld -> world();

    print 
    '<br />';

    echo 
    $helloworld -> monkey();

    ?>
    It works, and does exactly the same as what the others do XD
    Last edited by Zenax; 04-24-2007 at 05:07 AM. Reason: modified script
    Regards,
    Zenax

  10. #10
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP Tutorial

    There was no need for the second: $helloworld = new hello;
    Thanks,
    Brandon Long

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  5. Rewritten PHP Includes tutorial
    By [XiRE] in forum Tutorials
    Replies: 2
    Last Post: 07-28-2006, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers