Jump to content

I don't know nothing about PHP. I want to learn how.


Recommended Posts

For learning, you might try EasyPHP. It's free from sourceforge: http://sourceforge.net/projects/quickeasyphp

 

Another way to learn php is to just buy the cheapest hosting plan/domain you can that has php enabled. IXwebhosting is pretty nice. Then just use your favorite text editor, like Notepad++, and your favorite ftp client, like FileZilla, pick up a good book like "Programming PHP" by O'rielly books, and your set.

Link to comment
Share on other sites

hi,

 

Today I setup a PHP Testing Lab on the net http://phptesting.my10gb.com/index.php go to that, and in the large Text Area, try putting in some coding and it shows what it does below the text box.

 

With PHP, start by learning the basics. variables, if, if else, switch statements, all the basic statements in general. and

very first of all learn how the echo function works, and learn other functions.

 

ok, heres some of the basics.

 

Lesson 1 - PHP Tags, Echo Function, Commenting, and showing the end of a section of coding.

 

PHP tags mean, "this is where the code starts, and this is where the code finish's". the "this is where the code starts" tag is this. <?php , so when coding you first put that in. then at the end of your coding/script, you put ?> , and that states that, that is the end of your code/script. Next you need to know what comments are, comments is just parts you can put into your coding, to explain what the coding does, a single line comment starts with // before it, and a multi line starts with /* and ends with */ similar to the PHP tags, commenting is also used for disabling coding. To show the end of 1 little part/section of coding you use the semi-colon character ; . Now onto the Echo Function , well first of all, a function is a large amount of coding, that has been put into 1 basic bit of coding the function. The Most basic function in PHP would probably be the echo function, which is used for displaying stuff on a webpage. The function looks like the following. (also comment examples are in their as well)

 

<?php 

//This is a single line comment, anything put on this line will not be considered a code/script.
/* This is a  Multi Line Comment, anything put between
    these commenting tags will not be considered a code/script */

/* Below is the Echo Function, the word "echo" is the name of the function. what you want displayed on the webpage goes in between the brackets and a pair of double comma's, and their is a semi-colon their to show thats the end of the function code/script. */

echo( "Hello World" );

//Below is the Closing PHP tag to show that is the end of all the PHP Coding above.
?>

 

on a Web Page the echo function would display.

 

Hello World

 

I hope you understand my very FIRST lesson in PHP I have ever done  ;D

 

 

Lesson 2 - Variables, Basic Maths, and the echo function once again.

 

Variables are a simple form of storing little bits of information, such as a number, a word, or a phrase, or a combination of each. variables begin with a dollar sign, which tells PHP it is a variable $ , and after it has the name of the variable, you can name a variable whatever you want, as long as it only starts with a letter, although you can put numbers, and underscores in the name of a variable, it must always start with a letter. so an example of a variable and its name would be. it can also be of almost any length.

 

Correct Syntax (syntax meaning how it is set out.)

$variable
$variable_1
$a
$my_first_variable
$variable123

 

Incorrect Syntax

$123_variable
$1_variable
$_variable
$%#$@%
$__-

 

Now onto putting data/info into a variable. if you were to assign a number to a variable you could do it in the following way.

//Note you can use decimals aswell as numbers without decimals.
/* The Below variables would both be equal because they are both the number 1, although 1 has decimals and 1 doesnt. They are 2 separate variables because their names are different, so they wont be conflicting, you have to remember that no 2 variables can have the same name. and always remember to put the semi-colon at the end of a variable so it doesnt think their is more to the code/script then their really is.
*/
$variable = 1;
$variable1 = 1.00;

 

Now, the basic Mathematical Operators(symbols) in PHP are, - is subtract, + is addition, * is multiplication(not x), and / is divide. Now lets make 4 variables, and do a basic maths equation and display it on the page using the echo function. and we will assign a string to 1 of the variables(a string is just text, whether its one word or a sentence).

 

<?php

$x = 5;
$y = 2;

$string = "The sum of 5 and 2 is";

$result = "$x + $y";
$answer = "7";

$combining_them = "$string $answer";

echo($combining_them);

?>

 

That would display on a Webpage:

 

The sum of 5 and 2 is 7

 

And that concludes my First Ever Tutorial on PHP  :) , I hope it helps.

 

Regards MasterACE14

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.