Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
Hall of Famer's PHP Tutorials: Chapter 1 - PHP syntax
Chapter I - PHP Syntax Well this is the first part of my PHP tutorials, which is all about basic syntax of PHP. In this thread you will be able to learn basic PHP syntax, variables, data types and constants. Alright, lets get this started. 1. Getting started with PHP: If you have basic knowledge, you should understand the concept of tags. PHP tags enclose lines of PHP codes, you cannot write your PHP codes outside of tags. The start and end tags for PHP is shown below: PHP Code:
PHP Code:
PHP Code:
To display a message on the screen, we can use the functions print or echo. Strictly speaking, these are not the type of functions we normally refer to, since there is no need to enclose anything inside parenthesis(). An example is shown below: PHP Code:
At times it is rather necessary to write comments so that your codes make sense to you even if you have taken a long break from PHP programming. It will also help other programmers read your script files. To write comments, simply use double slashes in front of your sentences: PHP Code:
3. Variables: A variable is a type of container, which holds one particular value that can be of any data type. You can only assign one value to a variable, and the value can be changed at any time. To create a PHP variable, use the syntax: PHP Code:
PHP Code:
Another very important thing about variables is that its name can only contain letters, numbers or underscores. A variable name beginning with a number is not valid, nor is a variable that contains spaces. Examples of valid variable names are shown below: PHP Code:
PHP Code:
4. Data Types: Data types are not that important in PHP compared to C++ and Ruby, but it is still important to play around with them. There are six basic data types, namely: integer: 8, 99, 100000 double: 1.5, 2.6666, 3.14 boolean: true and false string: "Anna", "Hello World". array object null resource It may be necessary to see what data type a variable is currently holding. To do this, use the function below: PHP Code:
PHP Code:
PHP Code:
You may also use PHP's built-in functions is_datatype($var) to test if a variable contains the desired datatype. This types of functions return true if the variable contains the same datatype, or it returns false. They can be easily integrated with if...else statements. A list of this type of functions is shown below: PHP Code:
Constants, in contrast to variables, are containers storing values that cannot be changed later in your codes. To create a PHP constant, use the following syntax below: PHP Code:
PHP Code:
Alright, this is all for basic syntax. The next tutorial will introduce the concept of operators and how they work in PHP. This is my first time writing tutorials for PHP programming, lemme know if you have any suggestions on this. Thanks for reading this thread everyone, and have fun with Mysidia Adoptables script files. ^^
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#2
|
||||
|
||||
This helps a lot! Thanks! Unfortunately I'll have to read it a few more times because my brain is slow on coding. :3
__________________
Just because we all use the same script doesn't mean our websites can't be unique. Please visit Shop 12. |
#3
|
||||
|
||||
XD Its alright Knyfe, dont worry about it if you do not understand what I am saying in the first place. Its always the hardest to begin with, you will get used to programming with time.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#4
|
||||
|
||||
Thank you for posting these.
|
#5
|
||||
|
||||
You are very welcome. Cant say how much it helps, but I've decided to post more about PHP anyway. A support forum of a PHP based script definitely needs programming tutorials like this.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#6
|
||||
|
||||
So what is the difference between Print and Echo?.. Do they both just show whatever you put afterwords?
__________________
Hai there. :3 All I got for now. |
#7
|
|||
|
|||
Echo is slightly faster than print because it doesn't have a return value.
It's also 1 less character than print so it's really useful for the lazy people Echo can take multiple expressions while print can't. PHP Code:
|
#8
|
||||
|
||||
Quote:
__________________
Hai there. :3 All I got for now. |
#9
|
|||
|
|||
http://en.wikipedia.org/wiki/Return_statement
As far as I know, print always returns 1. Also I just found out that you can do the following with print but no echo PHP Code:
|
#10
|
||||
|
||||
Well a return value is quite simple to understand. Assume you have a math function f(x) = x^2 - 4x + 3, the x value is the input value, while the f(x) value is the return value. Print and echo are technically PHP functions, but of special type since you do not need to write a parenthesis to enclose anything inside these functions. Moreover, these functions' return values are themselves. This is pretty much like f(x) = x in math, in which f(x) has exactly the same value as x.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hall of Famer's PHP Tutorials: Chapter 6 - PHP Arrays | Hall of Famer | Tutorials and Tips | 0 | 03-16-2013 08:14 PM |
Hall of Famer's PHP Tutorials: Chapter 5 - PHP Function Basics | Hall of Famer | Tutorials and Tips | 0 | 11-23-2012 02:05 AM |
Hall of Famer's PHP Tutorials: Chapter 4 - PHP Iteration | Hall of Famer | Tutorials and Tips | 2 | 02-26-2011 10:48 AM |
Hall of Famer's PHP Tutorials: Chapter 3 - PHP Conditional Statements | Hall of Famer | Tutorials and Tips | 0 | 02-23-2011 06:59 PM |
Hall of Famer's PHP Tutorials: Chapter 2 - PHP Operators | Hall of Famer | Tutorials and Tips | 0 | 02-22-2011 08:26 PM |
What's New? |
What's Hot? |
What's Popular? |