I got really really bored so i just wrote this for fun, hope it is useful.
Rand() - generates a random number between minimum and maximum numbers specified.
ex:
Code: Select all
rand(1, 10)
_____
strpos() - used to find something in a string - case-sensitive
ex:
Code: Select all
$string = "Mary had a little lamb";
$find = "little";
$result = strpos($string, $find)
//if "little" was found, then $result would = 1, however, if it did not find it, $result would = 0.
//so if you wanted to check if it = zero, you would type:
if($result === 0) /* notice the 3 = signs? */
{
echo $find . " was not found.";
} else {
echo $find . " was found.";
}
strstr() - find the first occurance of a letter/number/special character in a string.
ex:
Code: Select all
$string = "Mary had a little lamb";
$find = " a";
$result = strstr($string, $find)
echo $result;
//"a little lamb"
//this is also a case sensitive type library function.
_____
stripos() - is the same as strpos() (see above) but case-insensitive.
_____
stristr() - same as strstr() (see above) - case-insensitive
_____
strlen() - get the length of a string.
ex:
Code: Select all
$string = "Mary had a little lamb";
$length = strlen($string)
echo "The string is " . $length . " character(s) long.";
_____
strrev() - reverse a string.
ex:
Code: Select all
$string = "Mary had a little lamb";
$reversed = strrev($string);
echo $reversed;
_____
strtr() - translates certain specified characters
ex:
Code: Select all
$string = "Màry hàd à little làmb";
$trans = strtr($string, "à", "a");
echo $trans;
_____
substr() - returns all characters between specified ending and beginning characters
ex:
Code: Select all
$string = "Mary had a little lamb";
echo substr($string, 0,4) // outputs: Mary
echo substr($string, 5, 3) outputs: had
md5() - encrypt a string into a md5 hash.
ex:
Code: Select all
$string = "Mary had a little lamb";
$encrypted = md5($string);
echo $encrypted;
_____
md5_file() - md5 a specified file
ex:
Code: Select all
/* assume mary.txt includes "Mary had a little lamb" */
$file = "mary.txt";
echo md5_file($file);
Explanation: Arrays.
Arrays are useful for many things, like holding lots of information in one variable, therefore, less variables
for you to remember. Often arrays are used in php flat file databases when someone does not wish to use an sql or other type of database. For instance, a user/password database.
heres an example:
Code: Select all
$user = array();
$user("a", "b", "c")
/* to get all information out of one of the values in the array, you would type:
echo $user[0] because the first element in array is counted as 0, and not 1. */
echo "List of users:<Br><Br>";
echo $user[0] . "<Br>";
echo $user[1] . "<br>";
echo $user[2] . "<Br>";
/* that would be a long and tedious task for someone that had alot of users in that array, so that's where we came
up with: count(ARRAY) which counts all values in the array here's an example of it's usage. */
echo "Current number of users in database: " . count($user);
in the array, easier.
_____
while() {} - used to loop code until broken.
ex:
Code: Select all
echo "List of users in database:<BR><BR>";
$a = 0;
while($a < count($user))
{
echo $user[$a] . "<Br>";
$a++;
}
_____
if() {} - used to compare
ex:
Code: Select all
$a = 1;
$b = 1;
$c = $a + $b;
if($c == 2)
{
echo "The variable "$c" does equal 2!";
} else {
echo "The variable "$c" does not equal 2.";
}
for() {} - most complex loops in PHP. They behave like their C counterparts. - quoted off of http://php.net
ex:
Note: This is using variables from the array explanation above.
Code: Select all
for($a = 0; $a < count($user); $a++)
{
echo $user[$a] . "<br>";
}
-------------
This guide was not copied off of any site, and was written in my own free time by me alone, any information used off of a site was given credit to that site.
- Gogeta70