php

Zend PHP5 certification Exam study review 1: Strings and Regular Expressions

January 4, 2008 · 4 min read

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 logicint 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]] )whitelistint 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-awarestring 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

← Back to all posts