Jump to content

  •  

  • iBotModz CBox


    Photo

    Beginning PHP - Lesson 4 - First PHP File


    This topic has been archived. This means that you cannot reply to this topic.
    1 reply to this topic

    #1 fattwam

    fattwam

      General Grade 2

    • Sub-Admins

    • 3,979 posts
    • Joined: 18-August 07

    Posted 27 March 2008 - 08:11 PM

    Now we are going to put the topics we disscussed in lessons 1-3 into practice.

    When you make a PHP file you have to name it '*.php' just like microsoft word documents are named '*.doc' and some images are '*.jpg'. If you don't name a file '*.php' - the PHP core won't process it, and it won't work.

    Open up "notepad" (I use/recomend the free SciTE Text Editor becuase it HIGHLIGHTS the different code!)or some other simple text editor(NOT MS WORD, or WORD PERFECT) and type the following:



    $site_name = "type some site of your own here";
    //the $site_name string
    $paragraph_text = "Type your welcome text here! type more text here!";
    // the first $paragraph string
    $email = 'type [email=your@email.com]your@email.com[/email]';
    //your email string
    $your_age = 00;
    // your age variable
    ?>




    Email me: [email=][/email]






    Once you are finished typing the text above, select "file", "Save as" and name it "test.php" with the quotes. By naming a file with quotes you are telling the computer not to name it something ".txt". For example, if you just name it test.php (without the quotes) and save it, when you go to the file it will be named "test.php.txt"!

    Now upload the file to your web server (FTP). If you don't know how to use FTP (File Transfer Protocol) to put web pages onto the internet, please read FTP 101 - A Beginner's Guide or An Introduction to FTP and I recommend you use the free SmartFTP client.


    If you are using "easyphp", "WAMP", or some other program/server on YOUR computer simply save or move the file to the correct folder (probably "C:wampwww" or something like that.)


    Once the file is in the correct place, point your browser to the location of the file and run it. If you are using a web server the file will be wherever you FTP'ed it to. (exmaple: "http://www.yoursite.com/test.php") If you are using a server on your own PC it should be something like "http://localhost/test.php"


    when you run the page you should see this:

    type some site of your own here
    Type your welcome text here! type more text here!
    Email me: type your@email.com

    If you hold your mouse over the page and "right-click" and select "view source" from the options - you will see this in the pop-up window:

    <html>
    <body>
    <h2>type some site of your own here</h2>
    <p>Type your welcome text here! type more text here!</p>
    <p>Email me: <a href="mailto:type your@email.com">type your@email.com</a>
    </body>
    </html>


    Where is all of the PHP code? Well PHP processed it all and then gave the result to the brower. It ran the php code and submitted the result to your computer to display. That is one of the beauties of PHP - No one knows what you type! No one can steal your code (javascript) and no one can "beat the system" by knowing what you are doing behind the scenes on your web site - so you are safer from hackers (As opposed to other languages).

    If you want a challenge make a file named "address.php" that prints your address from three different strings: (your name, street, and city/state/zip).

    Here is another php file that prints your Full Name:



    $first_name = "John";
    $second_name = "M.";
    $last_name = "Doe";
    ?>









    Now that you know what a "string" is - we can start doing some fun things with them!


    For more information please read these articles:



    Tizag

    CodeWalkers - Strings Primer

    PHP Manual

    Learn PHP Strings Ref

    Strings Regular Expressions (Advanced)

    Zend - Using Strings

    If you find a broken link please PM me, thanks!

    #2 SmokiestGrunl

    SmokiestGrunl

      Australian Retired Staff

    • Retired Staff

    • 3,888 posts
    • Joined: 02-September 07

    Posted 14 April 2008 - 04:12 AM

    These are my outcomes (first.php and second.php):

    http://ilearnsphp.php0h.com/

    Also I am new to php put I have experience in other languages and I must stress type out the codes, even though it is easy to copy and paste, you will learn much more if you type the code yourself.