Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
Welcome muare.forum-viet.com

[Class] How to code PHP 101 1466027_a28518e0bb72af535fc0

Latest topics
» Bạn nên biết điều kiện du học Hàn Quốc có
[Class] How to code PHP 101 EmptyMon 05 Oct 2015, 7:51 pm by giaychuotkhoet

» Hộp đựng đa năng trong phòng tắm và các đồ dụng tiện llợi khác
[Class] How to code PHP 101 EmptyWed 22 Jul 2015, 1:23 am by aloonline1987

» gel bôi trơn ấm áp warm lovin
[Class] How to code PHP 101 EmptyTue 19 May 2015, 4:24 pm by shopnguoilon_sg

» màng film tránh thai vcf dành cho chị em
[Class] How to code PHP 101 EmptyTue 19 May 2015, 4:19 pm by shopnguoilon_sg

» màng film tránh thai vcf dành cho chị em
[Class] How to code PHP 101 EmptyTue 19 May 2015, 4:17 pm by shopnguoilon_sg

» stud 100 khẳng định đẳng cấp phái mạnh
[Class] How to code PHP 101 EmptyFri 15 May 2015, 11:25 am by shopnguoilon_sg

» Lover aider máy mát xa dành cho nữ
[Class] How to code PHP 101 EmptyFri 15 May 2015, 11:23 am by shopnguoilon_sg

» cung cấp máy ép dĩa chất lượng
[Class] How to code PHP 101 EmptyFri 17 Apr 2015, 2:15 pm by huyenrio

» Máy in hình lên ly
[Class] How to code PHP 101 EmptyWed 25 Mar 2015, 2:44 pm by huyenrio

» Máy in hình lên áo
[Class] How to code PHP 101 EmptyWed 25 Mar 2015, 2:43 pm by huyenrio

»  trang trí cây thông noel ở vinh,cho thuê cây thông noel ở vinh,chuyển quà noel ở vinh
[Class] How to code PHP 101 EmptyFri 28 Nov 2014, 8:44 am by sunflowerhn83

» Máy in hạn sử dụng DMJ-B chính hãng, giá sốc
[Class] How to code PHP 101 EmptyThu 02 Oct 2014, 9:40 am by phamlinhnd1010

» Dạy cắm hoa chuyên nghiệp,dạy cắm hoa nghệ thuật,dạy cắt tỉa của quả ở T.p Vinh Nghệ An
[Class] How to code PHP 101 EmptyTue 30 Sep 2014, 10:10 am by haiha131276

» công ty Yên Phát chuyên phân phối, lắp đặt camera chính hãng giá rẻ nhất miền Bắc.
[Class] How to code PHP 101 EmptyFri 26 Sep 2014, 10:57 am by phamlinhnd1010

» HOT! Chung cư mini Xuân Đỉnh ở ngay giá chỉ từ 690 triệu 1 căn
[Class] How to code PHP 101 EmptyFri 26 Sep 2014, 10:44 am by xuantruong23


[Class] How to code PHP 101

Go down

[Class] How to code PHP 101 Empty [Class] How to code PHP 101

Bài gửi by Admin Sun 22 Aug 2010, 11:13 am

How to code PHP 101



Today, I would like to introduce everybody to my first tutorial here, I'm not sure if this is allowed but I'm going to go for it. I will be posting tutorials as I go along.


Where To Start Programming PHP

To begin programming PHP, I recommend learning how to code HTML first. PHP depends on HTML for input and other functions. If you have already learnt HTML, you should already have a code editor. (WYSIWYG editors may or may not have this feature) Normally PHP is only put on pages with the extension .php, but if the server is configured correctly you will be able to use it on extensions like .html and .htm. PHP stands for PHP: Hypertext Preprocessor. All php code starts with:
Code:
Although, this is not required if you have only php code on a page, or you are at the end of the page and putting some more code :P

Commenting PHP

In HTML to create a comment you would use
Code:
Whilst in php there are two types of comments, the single line and multi line, an example of a singe line comment:
Code:
The other way of commenting with single lines is:
Code:
To do a multi line comment:
Code:
Comments can be used anywhere and cannot be seen by users like HTML comments.

Variables

Unlike some other programming languages you may have learnt/used, PHP does not require their variables to be initialized before usage. Java Example:
Code:
int var;
var = 1;
PHP Example:
Code:
$var = 1;
There are many types of variables, but let's start with the three most basic types of variables; integers, booleans and strings. There are distinct differences between the three, like integers are only whole numbers. (no decimals, use float instead) Booleans are either true or false, but nothing else, and strings are simply anything you can type. Here are some examples, here is a integer:
Code:
$var = 1;
Here is a boolean:
Code:
$var = true;
Finally a string:
Code:
$var = "Hello";
A variable can be any type and the types are interchangeable. Unlike Java, where a variable could only be one type. You can make sure a variable is only one type, try using this example:
Code:
$var = (int) 1;
But after that line the $var can be changed to anything unless the (int) stays every time you change the variable.

Showing Information in the Browser with PHP

PHP has many ways of showing information, the most used, would be echo, it is not technically a function, but anyway, echo will write anything to the user's browser. An example of echo:
Code:
You can also use variable when echoing information, there are two ways, first way:
Code:
Or you could use this:
Code:
In place of echo (print should work in every place that echo works) you could use print like this:
Code:
To dump a variable, use either print_r or var_dump like this:
Code:
or with var_dump:
Code:

Loops

There are many ways in PHP to write code, but most likely loops are used for their flexibility and simplicity. There are many different types of loops for difference purposes.

The if/elseif/else loop:
Code:
if (condition)
{
Execute only if it meets the condition
}
else if (condition)
{
Execute only if it meets the condition and doesn't meet the previous condition
}
else
{
Execute only if it doesn't meet any of the previous condition(s)
}
NOTE: You can remove the (else if/else) if it isn't required in your code.

The for loop:
Code:
for (define variable;condition;execute after executing the code in the loop)
{
Execute only if it meets the condition
}

The foreach loop:
Code:
foreach (variable1 as variable2)
{
Execute for every variable in the array in variable1 but use variable2 to refer to the current variable in the array in variable1
}

The switch loop:
Code:
switch (variable)
{
case 'random':
Execute this code only if variable is equal to random
break;

case 'irregular':
Execute this code only if variable is equal to irregular
break;

default:
Execute this code only if variable is not equal to any of the previous option(s).
break;
}

Admin
Admin

Đánh giá tốt! : 7

Nam
Goat
Tổng số bài gửi : 10417
Birthday : 09/10/1979
Tuổi : 45
Địa chỉ: : Phú Yên
Điện thoại: : Mobile: (84) 0985 017 089
Điểm : 62150
Ngày đăng ký : 13/10/2007

https://muare.forum-viet.com

Về Đầu Trang Go down

Về Đầu Trang

- Similar topics

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết