First of all if you need information of PHP, read the basics.
Some tips if you faced problems.
-- Check the manual of PHP
-- If you didn't solve, make support thread here in otland.
-- If didn't get help at all, ask stackoverflow
After this tutorial, you will be able to write codes related to tibiaserver.
So let's start.
If you installed uniform, go to directory where you installed it, then open folder "www", remove all files inside and create a file named "index.php"
2 - For Linux users, this is a great tutorial, if you want to use nginx, here
The directory of "www/public_html" is mentioned in the tutorials, open it and chown it, then remove everything, and make index.php
The PHP grammar can be written only inside <?php ?>
To write a comment you can use "//" for line comment and "/* */ for long comment.
Learning basic functions.
PHP types :
To declare a variable we use : "$"
Colons ";" are used to end lines.
Before moving to string/integer functions we will get some information about "Arrays"
Before moving to Next step!
[Question] : What is difference between variable x and y in this code ?
String.
1) strlen($string), returns the length of a string.
2) Replacing texts in string.
There is two functions :
str_replace($tofind, $toreplace, $string) : case sensitive
str_ireplace(...same as str_replace..) : case insensitive
3) Lowercase or Uppercase string.
strtolower($string)
strtoupper($string)
I guess you have now a good background at functions.
To learn more and more functions go to W3schools or PHP.net.
Math ( applies to integers/floats ).
1) sin, cos, tan ($number)
as well asin, acos, atan($number) : arc *($number)
2) rand($min, $max) : random number from min to max.
You can leave $min, $max empty.
3) round($float)
Refer to manual of these function to learn more about it.
4) pow($base, $exp)
[30-04-2016, 10:55 CEST]
Example!
The switch statement ::
Can you execute same code on 2 conditions in if/switch statement?
Yes.
So after this point don't forget that ";" ends lines, "{ }" are used in functions, classes, ....
I will write more as soon as i am available.
Regards <3 .
Some tips if you faced problems.
-- Check the manual of PHP
-- If you didn't solve, make support thread here in otland.
-- If didn't get help at all, ask stackoverflow
After this tutorial, you will be able to write codes related to tibiaserver.
So let's start.
Step 1: Installing PHP, ( Apache or Nginx)
--------------------------------------------------------------------
1 - For windows users, for easiest approach install Uniform Server, alternatively you can install Apache manually.--------------------------------------------------------------------
If you installed uniform, go to directory where you installed it, then open folder "www", remove all files inside and create a file named "index.php"
2 - For Linux users, this is a great tutorial, if you want to use nginx, here
The directory of "www/public_html" is mentioned in the tutorials, open it and chown it, then remove everything, and make index.php
Step 2: learning all basics.
--------------------------------------------------------------------
PHP language is case-insensitive so doesn't matter you write `eChO` or `EcHo`--------------------------------------------------------------------
The PHP grammar can be written only inside <?php ?>
PHP:
<?php
// Php Code here
?>
To write a comment you can use "//" for line comment and "/* */ for long comment.
PHP:
// Comment here
No Comment here
/* Comment here
Also comment here
As well comment here :p */
Learning basic functions.
PHP:
/* echo : outputs all parameters */
echo "PHP"; // PHP
echo "PHP", " is ", " fun."; // PHP is fun
/* var_dump : outputs structure information. */
var_dump("PHP"); // string(3) "PHP"
// This function is commonly used for objects/arrays ( will learn them soon )
*/
To declare a variable we use : "$"
Colons ";" are used to end lines.
PHP:
$string = "String"; // String variable.
$integer = 19; // Integer variable
$float = 19.1; // Float(double) Variable, ...
$bool = true; // boolean(true/false)
PHP:
$m = array(); // Empty array
$s = []; // Aswell empty array.
// So there is two ways to declare an array.
$m = array(1, 2, 3);
$m = array("a" => 1, "b" => 2); // As you see, i can call variables and re-declare them.
/* How to call an index in the array? */
$array = [1, 2 ,3]; // What is this? Yah, an array.
var_dump( $m[0] ); // We talked before about var_dump;
// The result will be : int(1)
/* How to add index to array */
$array = array(1, 2, 3);
$array[] = 4; // This is a way;
array_push($array, 5); // This is another way;
var_dump($array);
/* result :
array(5) {
[0]=> int(1)
[1]=> int(2)
[2]=> int(3)
[3]=> int(4)
[4]=> int(5)
}
[x] mean index number.
*/
Before moving to Next step!
[Question] : What is difference between variable x and y in this code ?
PHP:
$x = "15";
$y = 15;
var_dump($x, $y);
The difference is that variable x is a string, but variable y is an integer.
Step 2: Deep in types.
--------------------------------------------------------------------
--------------------------------------------------------------------
String.
1) strlen($string), returns the length of a string.
PHP:
$x = "15";
var_dump(strlen($x)); // returns int(2)
There is two functions :
str_replace($tofind, $toreplace, $string) : case sensitive
PHP:
// Test to see result yourself.
$string = "I am not learning PHP";
var_dump ( str_replace("not learning", "learning", "$string") );
// This will return string(17) "I am learning PHP"
// Try to test this again.
var_dump ( str_replace("not Learning", "learning", "$string") );
// This will return string(21) "I am not learning PHP";
// yeah when we used capital L, it didn't replace anything.
str_ireplace(...same as str_replace..) : case insensitive
PHP:
$string = "I am not learning PHP";
var_dump ( str_ireplace("not learning", "learning", "$string") );
var_dump ( str_ireplace("not Learning", "learning", "$string") );
// Both will return string(17) "I am learning PHP"
3) Lowercase or Uppercase string.
strtolower($string)
strtoupper($string)
PHP:
$string = "HelLo PeoPle";
var_dump( strtolower($string) );
var_dump( strtoupper($string) );
To learn more and more functions go to W3schools or PHP.net.
Math ( applies to integers/floats ).
1) sin, cos, tan ($number)
as well asin, acos, atan($number) : arc *($number)
PHP:
// I guess you already know them from calculator.
$l = sin(30); // 0.5
$t = asin($l); // 30
You can leave $min, $max empty.
PHP:
$s = rand(10, 20); // well i can't guess the result ;p
$h = rand();
Refer to manual of these function to learn more about it.
PHP:
$l = round(9.15); // 9
$a = round(9.95) // 10
PHP:
$a = pow(3, 2); // 3 ^ 2 = 3 * 3 = 9
$l = pow(2, 3); // 2 ^ 3 = 2 * 2 * 2 = 8
[30-04-2016, 10:55 CEST]
Step 3: Conditions and loops
--------------------------------------------------------------------
--------------------------------------------------------------------
The if statement ::Conditional statements are used to perform different actions based on different conditions.
PHP:
/* if ... */
if (condition) {
// code to execute if condition is true
}
/* if ... else ... */
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
/* if ... else ... elseif ...*/
if (condition1) {
// code to execute if this condition1 is true;
} elseif (condition2) {
// code to execute if this condition2 is true and condition1 is false;
} else {
// code to execute if all conditions are false;
}
Example!
PHP:
$x = 20;
$h = 15
$y = 18;
if ($x > $y) {
echo "x is more than y";
} elseif ($h > $y) {
echo "h is more than y but x is less than y";
} else {
echo "x and h are less than y"
}
if ($x == 20) {
echo "x is equal to 20";
}
The switch statement ::
PHP:
switch (something) {
case label1 :
// code to execute if something==label1
case label2 :
// code to execute if something==label2
default :
// code to execute if something doesn't meet any of cases!
}
Can you execute same code on 2 conditions in if/switch statement?
Yes.
PHP:
// in if you can use (&&) which means and, (||) which means or.
if ($x == $a || $x == $b) {
....
}
// in switch statement
switch (something) {
case label1 : case label2 :
// dosomething when (something == label1 || something == label2)
default :
...
}
So after this point don't forget that ";" ends lines, "{ }" are used in functions, classes, ....
I will write more as soon as i am available.
Regards <3 .
Last edited: