Zend PHP5 certification Exam study review 1: Strings and Regular Expressions
In this post, I list some of the aspects that you may need to refresh your memory on PHP5’s String and Regular Expressions feature. String and Regx are very important for any web development language, so you should have great grasp on them before you take the Exam. The funcitons listed here are no guarantee will be tested in the exam, they are just what I thought you should know them. Of course, these are just a fraction of the functions on php.net; I encourage you visit php official manual often!
int strlen ( string $string )
string strtr ( string $str, string $from, string $to )
string strtr ( string $str, array $replace_pairs )
int strcmp ( string $str1, string $str2 )
int strcasecmp ( string $str1, string $str2 )
Note: PHP first transparently converts strings to their numeric equivalent; use “===” in the IF logic
int strpos ( string $haystack, mixed $needle [, int $offset] )
int stripos ( string $haystack, string $needle [, int $offset] )
int strrpos ( string $haystack, string $needle [, int $offset] )
string strstr ( string $haystack, string $needle )
string stristr ( string $haystack, string $needle )
int strspn ( string $str1, string $str2 [, int $start [, int $length]] ) whitelist
int strcspn ( string $str1, string $str2 [, int $start [, int $length]] ) blacklist
mixed str_replace ( mixed $search, mixed $replace, mixed $subject [, int &$count] )
mixed str_ireplace ( mixed $search, mixed $replace, mixed $subject [, int &$count] )
mixed substr_replace ( mixed $string, string $replacement, int $start [, int $length] )
The result string is returned. If string is an array then array is returned
string substr ( string $string, int $start [, int $length] )
string number_format ( float $number [, int $decimals [, string $dec_point, string $thousands_sep]] ) not locale-aware
string money_format ( string $format, float $number ) locale aware
The money_format() function is not available onWindows, as well as on some variants of UNIX.
string setlocale ( int $category, string $locale [, string $...] )
string setlocale ( int $category, array $locale )
Printf Family print(), sprintf(), vprintf(), sscanf(), fscanf()
——————————————————————————————————
int printf ( string $format [, mixed $args [, mixed $...]] )
commonly-used type specifiers:
% - a literal percent character. No argument is required.
b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2).
u - the argument is treated as an integer, and presented as an unsigned decimal number.
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).
Perl-compatible Regular Expressions
Delimiters By convention, the forward slash is used
Metacharacters
\d Digits 0-9
\D Anything not a digit
\w Any alphanumeric character or an underscore (_)
\W Anything not an alphanumeric character or an underscore
\s Any whitespace (spaces, tabs, newlines)
\S Any non-whitespace character
. Any character except for a newline
Quantifiers
? Occurs 0 or 1 time
* Occurs 0 or more times
+ Occurs 1 or more times
{n} Occurs exactly n times
{,n} Occurs at most n times
{m,} Occurs m or more times
{m,n} Occurs between m and n times
Sub-Expressions compare this to the “range” e.g. [1-9]
PCRE – Pattern Modifiers
– i – Case insensitive search
– m – Multiline, $ and ^ will match at newlines
– s – Makes the dot metacharacter match newlines
– x – Allows for commenting
– U – Makes the engine un-greedy
– u – Turns on UTF8 support
– e – Matched with preg_replace() allows you to call
Functions:
int preg_match ( string $pattern, string $subject [, array &$matches [, int $flags [, int $offset]]] )
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern,
$matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
int preg_match_all ( string $pattern, string $subject, array &$matches [, int $flags [, int $offset]] )
mixed preg_replace ( mixed $pattern, mixed $replacement, mixed $subject [, int $limit [, int &$count]] )
to reuse captured subpatterns directly in the substitution string by prefixing their index with a dollar sign
Just like with str_replace(), we can pass arrays of search and replacement arguments; however, unlike str_replace(), we can also pass in an array of subjects on which to perform the search-and-replace operation. This can speed things up considerably, since the regular expression (or expressions) are compiled once and reused multiple times.
Thank you for reading this post. You can now Leave A Comment (0)
Post Info
This entry was posted on 4 January 2008 8:40 PM and is filed under php tagged with:Technology,web development,zend certification,phpYou can follow any responses to this entry through the Comments Feed. You can Leave A Comment , or A Trackback .
Previous Post: Passing the Zend PHP 5 Certification Exam »
Next Post: Zend PHP5 Certification Exam study review 2: Streams And Network »
- Review, php|architect’s Guide to Programming with Zend Framework
- Use Writer, the online Darkroom version!
- Learn to Design Web Themes and Templates with New Wiki
- Emergency Aid for Chinese Earthquake: Need 2,6 million Tents right now!
- WordPress problem: Url encoding on Tag’s slug.
- Curl better than simplexml_load_file when web screen scrapping
- How to use SimpleXML parsing XML data with namespace and CDATA
- The philosophy of life
- Zend PHP5 certification Exam study review 12: supplementary III
- Zend PHP5 certification Exam study review 11: supplementary II
chinese











