Wednesday, November 25, 2009






Saturday, November 14, 2009

PHP Internals

1 Strings
2 Numbers
3 Time and Date
4 Variables
5 Arrays
6 Functions
7 Classes and Objects
8 Files and Directories


1 Strings:
Quick learn:
Find the length of a string:

$length = strlen($string);
This function returns the number of characters in a string.

Full documentation: http://php.net/strlen

Split a string using a string as a separator:

$array_of_strings = explode($separator, $string);
This function returns the array of substrings created by splitting a string at every point the separator string appears.

Full documentation: http://php.net/explode

Create a string from an array of strings, with a separator:

$string = implode($separator, $array_of_strings);
The returned string will be a concatenation of all the strings in the array, with the separator string between them.

Full documentation: http://php.net/implode

Remove extra space from the beginning and end of a string:

$trimmed_string = trim($string);
The returned string will have any whitespace characters removed from the beginning and end of the string. The functions rtrim() and ltrim() remove whitespace from only the right or left end of the string, respectively.

Full documentation: http://php.net/trim, http://php.net/rtrim, and http://php.net/ltrim

Replace all occurrences of one string with another string:

$result_string = str_replace($old, $new, $full);
All occurrences of the old string within the full string are replaced with the new string. A case-insensitive version is also available as the function str_ireplace().

Full documentation: http://php.net/str_replace and http://php.net/str_ireplace

Pad a string to a specified length:

$padded = str_pad($string, $length);
The returned string is at least $length characters long. Spaces are added to the right of the string to achieve this. With optional arguments, any string can be used as padding along with whether the padding will occur at the beginning or end of string.

Full documentation: http://php.net/str_pad

Create a larger string via repetition:

$repeat = str_repeat($string, $nrepeats);
The input string is replicated the specified number of times to create the result.

Full documentation: http://php.net/str_repeat:

Split a string into an array of characters

$array = str_split($string);
This function returns an array comprising the characters that make up the string.

Full documentation: http://php.net/str_split

Return a portion of a string:

$substring = substr($string, $n, $length);
The portion of the string starting at the nth character for $length number of characters is returned. If $n is negative, the substring will start that many characters from the end of the string. If $length is negative, that many characters will be omitted from the end of the string.

Full documentation: http://php.net/substr

Make a string all uppercase or lowercase letters:

$lower = strtolower($string);

$upper = strtoupper($string);
These functions simply return, respectively, the lowercase or uppercase versions of the string.

Full documentation: http://php.net/strtolower and http://php.net/strtoupper

Parse a string based on a format:

$array = sscanf($string, $format);
The returned array contains each extracted value from the string according to the specified format.

Full documentation: http://php.net/sscanf

Output values using well-defined formats:

printf($format, $var1, $var2,...);
Using a simple syntax, the format argument defines how the subsequent arguments are printed. This function is part of a family of formatting functions.

Full documentation: http://php.net/printf, http://php.net/sprintf, http://php.net/fprintf

Compare two strings:

$result = strcmp($string1, $string2);
This function returns a number less than, equal to, or greater than 0 depending on how the strings compare alphabetically. 0 is returned if the strings are equivalent. A case-insensitive version is also available as strcasecmp().

Full documentation: http://php.net/strcmp and http://php.net/strcasecmp

Compare two strings as a human would do so:

$result = strnatcmp($string1, $string2);

$result = strnatcasecmp($string1, $string2);
The comparison is based on how people order stringsthat is, strings with numbers in them are ordered based on value, not just characters. The comparison is case-sensitive for the former call while being case-insensitve for the latter.

Full documentation: http://php.net/strnatcmp

Determine where the first occurrence of a string is within another string:

$pos = strpos($bigstring, $search);
This function returns the position of the search string in $bigstring. If not found, false is returned. A case-insensitive version is also available as stripos().

Full documentation: http://php.net/strpos and http://php.net/stripos

Determine where the last occurrence of a string is within another string:

$lastpos = strrpos($bigstring, $search);
This function returns the position of the last occurrence of the search string in $bigstring. If not found, false is returned. A case-insensitive version is also available as strripos().

Full documentation: http://php.net/strrpos and http://php.net/strripos

Search for any of a set of characters within a string:

$found = strpbrk($string, $characters);
The string is scanned for any of the characters in the $characters string. If a match is found, it returns a string starting from the character it just matched to the end of the string.

Full documentation: http://php.net/strpbrk

facebook

International movers in newyork, Long distance movers in newyork, Automobile movers in newyork , Temporary storage, Moving supplies, moving overseas, international shipping, shipping, free quotes, moving quotes, moving company, international removals, removal company.Please visit here: baileysworldwide.com ====================================================== debris removal in nyc, garbage removal in nyc, debris removal in queens, demolition removal in queens, garbage removal in queens, garbage removal in New York.Please visit here : Richmond HILL demolition & garbage removal ======================================================= NYC work permit, NYC violation removal, Alt I, Alt II, Alt III filings,(interior, commercial build outs), New Building, Builders Pavement Plan (BPP), Sign applications, Sprinkler Fire alarm applications, Place of Assembly, Temporary Place of Assembly, Stop Work Order Removal. Please visit here : chameleonexpediting.com