Loading....
Name | Description |
---|---|
__LINE__ |
The current line number of the file. |
__FILE__ |
The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances. |
__DIR__ |
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.) |
__FUNCTION__ |
The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. |
__CLASS__ |
The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in. |
__TRAIT__ |
The trait name. (Added in PHP 5.4.0) As of PHP 5.4 this constant returns the trait as it was declared (case-sensitive). The trait name includes the namespace it was declared in (e.g. Foo\Bar). |
__METHOD__ |
The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive). |
__NAMESPACE__ |
The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0). |
money_format — Formats a number as a currency string
[php]<?php
$number = 1234.56;
// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56
[/php]
[php]
// Italian national format with 2 decimals`
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
// Eu 1.234,56
// Using a negative number
$number = -1234.5672;
// US national format, using () for negative numbers
// and 10 digits for left precision
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($ 1,234.57)
// Similar format as above, adding the use of 2 digits of right
// precision and '*' as a fill character
echo money_format('%=*(#10.2n', $number) . "\n";
// ($********1,234.57)
// Let's justify to the left, with 14 positions of width, 8 digits of
// left precision, 2 of right precision, withouth grouping character
// and using the international format for the de_DE locale.
setlocale(LC_MONETARY, 'de_DE');
echo money_format('%=*^-14#8.2i', 1234.56) . "\n";
// Eu 1234,56****
// Let's add some blurb before and after the conversion specification
setlocale(LC_MONETARY, 'en_GB');
$fmt = 'The final value is %i (after a 10%% discount)';
echo money_format($fmt, 1234.56) . "\n";
// The final value is GBP 1,234.56 (after a 10% discount)
?>
[/php]
fmod — Returns the floating point remainder (modulo) of the division of the arguments [php]<?php $x = 5.7; $y = 1.3; $r = fmod($x, $y); // $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7 ?> [/php] ceil — Round fractions up [php]<?php echo ceil(4.3); // 5 echo ceil(9.999); // 10 echo ceil(-3.14); // -3 ?> [/php] round — Rounds a float [php]<?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?>[/php] number_format — Format a number with grouped thousands [php]<?php $number = 1234.56; // english notation (default) $english_format_number = number_format($number); // 1,235 // French notation $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,56 $number = 1234.5678; // english notation without thousands separator $english_format_number = number_format($number, 2, '.', ''); // 1234.57 ?> [/php]
object
.
[php]<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read')); // return bool(true) if function exist
?>[/php]
func_num_args — Returns the number of arguments passed to the function
[php]
<?php
function foo()
{
$numargs = func_num_args();
echo "Number of arguments: $numargs\n";
}
foo(1, 2, 3);
?>
[/php]
Output:
Number of arguments: 3
[abc] |
A single character of: a, b or c |
[^abc] |
Any single character except: a, b, or c |
[a-z] |
Any single character in the range a-z |
[a-zA-Z] |
Any single character in the range a-z or A-Z |
^ |
Start of line |
$ |
End of line |
\A |
Start of string |
\z |
End of string |
. |
Any single character |
\s |
Any whitespace character |
\S |
Any non-whitespace character |
\d |
Any digit |
\D |
Any non-digit |
\w |
Any word character (letter, number, underscore) |
\W |
Any non-word character |
\b |
Any word boundary |
(...) |
Capture everything enclosed |
(a|b) |
a or b |
a? |
Zero or one of a |
a* |
Zero or more of a |
a+ |
One or more of a |
a{3} |
Exactly 3 of a |
a{3,} |
3 or more of a |
a{3,6} |
Between 3 and 6 of a |
Regular Expression | Will match... |
foo | The string "foo" |
^foo | "foo" at the start of a string |
foo$ | "foo" at the end of a string |
^foo$ | "foo" when it is alone on a string |
[abc] | a, b, or c |
[a-z] | Any lowercase letter |
[^A-Z] | Any character that is not a uppercase letter |
(gif|jpg) | Matches either "gif" or "jpeg" |
[a-z]+ | One or more lowercase letters |
[0-9\.\-] | ?ny number, dot, or minus sign |
^[a-zA-Z0-9_]{1,}$ | Any word of at least one letter, number or _ |
([wx])([yz]) | wy, wz, xy, or xz |
[^A-Za-z0-9] | Any symbol (not a number or a letter) |
([A-Z]{3}|[0-9]{4}) | Matches three letters or four numbers |
Regular Expressions Reference Sheet | ||
Character | Definition | Example |
^ | The pattern has to appear at the beginning of a string. | ^cat matches any string that begins with cat |
$ | The pattern has to appear at the end of a string. | cat$ matches any string that ends with cat |
. | Matches any character. | cat. matches catT and cat2 but notcatty |
[] | Bracket expression. Matches one of any characters enclosed. | gr[ae]y matches gray or grey |
[^] | Negates a bracket expression. Matches one of any characters EXCEPT those enclosed. | 1[^02] matches 13 but not 10 or12 |
[-] | Range. Matches any characters within the range. | [1-9] matches any single digit EXCEPT 0 |
? | Preceeding item must match one or zero times. | colou?r matches color or colour but not colouur |
+ | Preceeding item must match one or more times. | be+ matches be or bee but not b |
* | Preceeding item must match zero or more times. | be* matches b or be orbeeeeeeeeee |
() | Parentheses. Creates a substring or item that metacharacters can be applied to | a(bee)?t matches at or abeet but not abet |
{n} | Bound. Specifies exact number of times for the preceeding item to match. | [0-9]{3} matches any three digits |
{n,} | Bound. Specifies minimum number of times for the preceeding item to match. | [0-9]{3,} matches any three or more digits |
{n,m} | Bound. Specifies minimum and maximum number of times for the preceeding item to match. | [0-9]{3,5} matches any three, four, or five digits |
| | Alternation. One of the alternatives has to match. | July (first|1st|1) will match July 1stbut not July 2 |
POSIX Character Classes | ||
Character | Definition | Example |
[:alnum:] | alphanumeric character | [[:alnum:]]{3} matches any three letters or numbers, like 7Ds |
[:alpha:] | alphabetic character, any case | [[:alpha:]]{5} matches five alphabetic characters, any case, like aBcDe |
[:blank:] | space and tab | [[:blank:]]{3,5} matches any three, four, or five spaces and tabs |
[:digit:] | digits | [[:digit:]]{3,5} matches any three, four, or five digits, like 3, 05, 489 |
[:lower:] | lowercase alphabetics | [[:lower:]] matches a but not A |
[:punct:] | punctuation characters | [[:punct:]] matches ! or . or , but not a or 3 |
[:space:] | all whitespace characters, including newline and carriage return | [[:space:]] matches any space, tab, newline, or carriage return |
[:upper:] | uppercase alphabetics | [[:upper:]] matches A but not a |
Perl-Style Metacharacters | ||
Character | Definition | Example |
// | Default delimiters for pattern | /colou?r/ matches color or colour |
i | Append to pattern to specify a case insensitive match | /colou?r/i matches COLOR orColour |
\b | A word boundary, the spot between word (\w)and non-word (\W) characters | /\bfred\b/i matches Fred but notAlfred or Frederick |
\B | A non-word boundary | /fred\B/i matches Frederick but notFred |
\d | A single digit character | /a\db/i matches a2b but not acb |
\D | A single non-digit character | /a\Db/i matches aCb but not a2b |
\n | The newline character. (ASCII 10) | /\n/ matches a newline |
\r | The carriage return character. (ASCII 13) | /\r/ matches a carriage return |
\s | A single whitespace character | /a\sb/ matches a b but not ab |
\S | A single non-whitespace character | /a\Sb/ matches a2b but not a b |
\t | The tab character. (ASCII 9) | /\t/ matches a tab. |
\w | A single word character - alphanumeric and underscore | /\w/ matches 1 or _ but not ? |
\W | A single non-word character | /a\Wb/i matches a!b but not a2b |
PHPExcel - Formating cell and Number Format css formating