Page 1 of 2 12 LastLast
Results 1 to 10 of 34

Thread: Want to Learn Php..?? Here is the Way...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    342

    Default Want to Learn Php..?? Here is the Way...

    Here we are beginning a journey that reaches to Php. Feel that during this journey we are reading a book that describes the very php:

    We are not going to attempt to cover every single facet of the Wide World Of PHP Language. No, we want to grasp the basics of the language, get familiar with it, and get some real-life examples...not have the whole thing shoved down our throat!

    You might not find that web programming is the most exciting thing on the planet. Well, I don’t either, so I tried to make it interesting and easy to read.

  2. #2
    Join Date
    Jun 2008
    Posts
    342

    Default A journey leads to php....

    Presentation

    The examples in this book are presented in 3 levels - The Easy Stuff, The Not So Easy Stuff, and Oh Man Not MySQL!

    The Easy Stuff consists of common PHP commands you can use on just about any site you build. The Not So Easy Stuff is code that is a little more difficult to grasp, but you might still want to use it. Oh Man Not MySQL! will cover - you guessed it - how to connect to a MySQL database and do basic things, like writing to it and retrieving information.

    And now, without futher ado....

  3. #3
    Join Date
    Jun 2008
    Posts
    342

    Default A journey leads to php....

    Section 1

    The Easy Stuff

    (Covering ECHO, STRING, DATE, VARIABLES, INCLUDE, REQUIRE, and HEADER)

    Before we get into learning how to use PHP, we need to briefly explore what PHP is...but I’m not going to go into some long drawn out history of PHP and why it’s here. Also, it is good to be familiar with HTML before you proceed, as you will need to be able to copy and paste code in web pages.

    In the world of the wide web, there are two general types of coding languages: “Server side” and “Client side”. This means that one type is run, or interpreted, on the web server itself, and the other is run in your web browser.

    Think of it this way...
    Server side: You order a sandwich at a restaurant. It comes to you already prepared and ready to eat.
    Client side: You order a sandwich at a restaurant. Individual sandwich parts (bread, meat, lettuce, tomatoes, condiments) are delivered to you separately and you have to assemble them before you eat.


    PHP is a Server side language. All of the processing is done on the web server itself, and the result is delivered to your web browser as HTML (which, by the way, is a Client side language). Your web server must also have PHP installed in order for it to work! Most web hosting providers have PHP installed, so if you are in doubt, simply ask them.

    Things To Note:
    There are three things that need to happen before the web server correctly runs a PHP command.
    • The filename must be “file.php” instead of the usual “file.htm” or “file.html”. If it has the HTM or HTML extension, the PHP engine on the web server will ignore it. (There are exceptions to this, but we won’t go into them right now.)


    • The PHP code must be within the <?php and ?> tags. If it is not, the PHP engine on the web server will ignore it.


    • Each PHP line must end with a Semicolon. If it does not, you’re going to get some cryptic error messages.




  4. #4
    Join Date
    Jun 2008
    Posts
    342

    Default A journey leads to php....

    Now, Let’s Code!

    We’re going to tackle the basics to start with. Getting PHP to write things to the web browser, what variables are and how to use them...examples you can use in just about every web page you create.

    Let’s start with the most basic one.

    The PHP Echo command

    We’re going to tell PHP to output something to the screen. Keep in mind that PHP can be used in conjunction with HTML, but we are not showing the code in this example, to keep it simple:

    <?php echo “Creamy Bagels”; ?>

    Let’s dissect the command example bit by bit, shall we? It helps to do this when you are looking at a LOT of PHP code...because, trust me, it can look like a jumbled blurry mess sometimes if you don’t take it piece by piece! So next time, please, if you will...

    <?php - tells the server to process this as php code...

    echo “Creamy Bagels” ; - tells the server to write what’s in the quotes to the screen, and that the semicolon is ending this particular command...

    ?> - tells the webserver, “OK, I’m done with PHP for now. Back to regular HTML”.

    Pretty simple when you look at it that way, yes?

    OK, that’s cool..but what if I want to see quotes on my screen?” Want to know ? Wait....

    This can be done by “escaping” the PHP code for what you want to show up in quotes. Let’s use the example from above...

    <?php echo “Creamy Bagels”; ?>

    If you wanted to see quotes around Creamy Bagels, you would use the following code instead:

    <?php echo “\”Creamy Bagels\””; ?>

    Using \” tells PHP that you want a quotation mark to appear. Remember this - we’re going to use it later!

  5. #5
    Join Date
    Jun 2008
    Posts
    342

    Default A journey leads to php....

    Pull some Strings...

    In PHP, as a general rule, a String is any line of text contained within quotation marks. You can use either double quotation marks (“) or single quotation marks also known as apostrophes (‘) in a string. Strings could be considered the building blocks of PHP, considering most all data is going to come from what’s in a string.

    <?php
    $double = "quotation marks.";
    $single = 'single quotes.';
    ?>


    When using single quotes, you need to “escape” the apostrophe with the slash (just like you would with double quotation marks) if you wish to display it in the output text...

    <?php
    echo 'Wouldn\'t you like a bagel?';
    ?>


    Special commands within strings...

    There are some “secret commands” you can use within strings to manipulate the output text:

    \n: makes a new line
    \r: a carriage return
    \t: a tab
    \$: shows a dollar sign
    - remember PHP will be looking for a variable if you want to display a dollar sign and don’t use a slash...and throw an ugly error!

  6. #6
    Join Date
    Jun 2008
    Posts
    342

    Default A journey leads to php....

    Using Variables

    A Variable in PHP, simply put, is one thing that means another thing or things - a “container” if you will. It can represent text, numbers, calculations, and more.

    Variables are quite powerful, and if you mess ‘em up, they’ll come get you in the middle of the night.

    Declaring a variable is easy. No spaces in the variable name, please - PHP doesn’t like that...

    <?php
    $This_thing = “The Other Thing”;
    ?>


    Now before you go off saying “What the heck would I need THAT for?”, remember that variables are very useful...especially if you are PHP Include-ing other files (Like the foreshadowing there? Do ya?)

    Real World Usage For Variables

    Here’s an example of how you can use a variable in the real world: show the current date on your website.

    <?php
    $today = date("F j, Y");
    echo "$today";
    ?>


    This example sets the date command as a variable called “$today”, and uses echo to display it on the screen.

  7. #7
    Join Date
    Aug 2009
    Posts
    4

    Default

    this is free phpnuk hosting.free and easy make your forum:
    www.greatnuk.com

  8. #8
    Join Date
    Apr 2009
    Posts
    1

    Default

    thanks man

  9. #9
    Join Date
    Oct 2005
    Location
    Ernakulam
    Posts
    1

    Default

    thanx a lot for this tut.!

  10. #10
    Join Date
    May 2009
    Posts
    3

    Default

    WOW!
    this is a good One. I've bookmarked it for future reference. this time I'll concentrate on my web page designing. CSS and HTML
    Then back here when I'm ready.

    Thanks a lot

Page 1 of 2 12 LastLast

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
  •