Operator | Description |
---|---|
+ | Add two numbers |
- | Subtract the second number from the first number |
* | Multiply two numbers |
/ | Divide the first number by the second number |
% | Find
the remainder when the first number is divided by the second number. This is called the modulus. Example: $a = 13 % 4, $a is set to 1. 13 divided by 4 is 3, with a remander of 1 because 13 minus 12 is 1. |
$string1 = 'Hello';
$string2 = 'World!';
$stringall = $string1.$string2;
echo $stringall
Symbol | Meaning | Example |
---|---|---|
F | Month in text, not abbreviated | January |
M | Month in text, abbreviated | Jan |
m | Month in numbers with leading zeros | 02, 12 |
n | Month in numbers without leading zeros | 2, 12 |
d | Day of the month; two digits with leading zeros | 03, 30 |
j | Day of the month; two digits without leading zeros | 3, 30 |
l | Day of the week in text, not abbreviated | Friday |
D | Day of the week in text, abbreviated | Fri |
w | Day of the
week in numbers where 0 is Sunday, 1 is Monday, 6 is Saturday |
1 |
Y | Year in four digits | 2008 |
y | Year in two digits | 02 |
g | Hour between 0 and 12 without leading zeros | 2, 12 |
G | Hour between 0 and 24 without leading zeros | 2, 15 |
h | Hour between 0 and 12 with leading zeros | 01, 10 |
H | Hour between 0 and 24 with leading zeros | 00, 23 |
i | Minutes | 00, 59 |
s | Seconds | 00, 59 |
a | am or pm in lowercase | am, pm |
A | AM or PM in uppercase | AM, PM |
description | words and abbreviations |
---|---|
Month names | Twelve month names and abbreviations |
Days of the week | Seven days and some abbreviations |
Time units | year, month, fortnight, week, day, hour, minute, seconds, am, pm |
Some useful English words | ago, now, last, next, this, tomorrow, yesterday |
Plus and minus | + or - |
All numbers | |
Time zones | examples: gmt (Greenwich Mean Time), pdt (Pacific Daylight Time), akst (Alaska Standard Time) |
$importantDate = strtotime("tomorrow"); #24 hours from now |
$importantDate = strtotime("now + 24 hours"); |
$importantDate = strtotime("last saturday"); |
$importantDate = strtotime("2 weeks ago "); # current time |
$importantDate = strtotime("next year gmt "); |
$importantDate = strtotime("now + 24 hours"); |
$importantDate = strtotime("this 4am"); # 4 AM today |
Comparison | Description |
---|---|
== | Are the two values equal ? |
> | Is the first value larger than the second value ? |
>= | Is the first value larger or equal to the second value ? |
< | Is the first value smaller than the second value ? |
<= | Is the first value smaller or equal to the second value ? |
!= | Are the two values not equal to each other ? |
<> | Are the two values not equal to each other ? |
if ( $gender == "female" )
{
$tempGender = $gender;
$swt = "on";
}
Character | Meaning | Example | Match | Not a Match |
---|---|---|---|---|
^ | Begining of line | ^c | cat | my cat |
$ | End of line | c$ | tic | stick |
. | Any single character | . . | any string that contains at least two characters | a,i |
? | Preceding character is optional | mea?n | mean, men | moan |
( ) | Groups literal characters into a string that must be matched exactly | m(ea)n | mean | men, mn |
[ ] | Encloses a set of optional literal characters | m[ea]n | men, man | mean, mn |
- | Represents all the characters between two characters | m[a-c]n | man, mbn, mcn | mdn, mun, maan |
+ | One or more of the preceding items | door[1-3]+ | door111, door131 | door, door55 |
* | Zero or more of the preceding items | door[1-3]* | door, door311 | door4, door445 |
{ , } | The starting and ending numbers of a range of repetitions | a{2,5} | aa, aaaaa | a, xx3 |
\ | The following character is literal | m\*n | m*n | men, mean |
( | | ) | A set of alternate strings | (Tom|Tommy) | Tom, Tommy | Thomas, To |
Comparison | Description | Order |
---|---|---|
and | both conditions are true | first |
xor | one comparison is true, but not both | second |
or | one or both comparisons are true | third |
Condition | Is True If |
---|---|
$customer == "Smith" or $customer == "Jones" | The customer is named Smith or Jones |
$customer == "Smith" and $custState == "NY" | The customer is named Smith and the state is NY |
$customer == "Smith" or $custState == "NY" | The customer is named Smith or the state is NY |
$customer == "Smith" xor $custState == "NY" | The customer
is named Smith or the state is NY but not both |
$customer != "Smith" and $custAge < 13 | The customer's name is not Smith and the age is under 13 |