PHP Developer’s Dictionary IT-SC book 175 Description The sprintf() function returns a string made up of the arg s, which have had the format applied to them. The format string is made up of zero or more directives: ordinary characters (excluding % ) that are copied directly into the result, along with conversion specifications, each of which results in fetching its own parameter. Each conversion specification consists of these elements, in order: padding specifieris an optional parameter that specifies which character to use if padding is necessary to adjust the string to a larger size. The default is to pad with spaces, but can also be specified as the 0 (zero character). To specify an alternative padding character, precede the character with a single quote ('). alignment specifier is an optional parameter that indicates whether the resulting string should be right- or left-justified. The default is right- justified, and a "-" character is used to indicate left justification. width specifier is an optional number that specifies the minimum number of characters the result should contain. precision specifier is an optional parameter that specifies the number of decimal digits that should be displayed for floating-point numbers. This applies only to numbers of type double. type specifier specifies the type as which the argument should be treated. Possible types as which the argument can be treated are %— Treat as a percent character. No argument is required. b— Treat as an integer and present as a binary number. c— Treat as an integer and present as the character with the corresponding ASCII value. d—Treat as an integer and present as a decimal number. f— Treat as a double and present as a floating-point number. o— Treat as an integer and present as an octal number. s— Treat and present as a string. x— Treat as an integer and present as a hexadecimal number (with lowercase letters). X— Treat as an integer and present as a hexadecimal number (with uppercase letters). PHP Developer’s Dictionary IT-SC book 176 $type = "checking"; $balance = 500; $text = sprintf("type = %s, balance = %2.2f",$type,$balance); echo $text;//displays type = checking, balance= 500.00 strcasecmp() Syntax int strcasecmp(string str1, string str2) Description The strcasecmp() function, which was added in PHP 3.0.2 and PHP 4.0, returns a negative number if str1 < str2 , a positive number if str2 > str1 , and 0 if both strings are equal. The comparison is case insensitive. echo strcasecmp ("abc","xyz");//displays -23 echo strcasecmp ("xyz","abc");//displays +23 echo strcasecmp ("abc","ABC");//displays 0 strchr() Syntax string strchr(string haystack, string needle) Description The strchr() function finds the first occurrence of a string. It returns all of haystack starting at the first occurrence of needle . If needle is not found in haystack , false is returned. If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. The ordinal value is the corresponding value from an ASCII table; for example, 65 = 'A'. echo strchr ("XXXXAXXXX",65);//displays AXXXX strcmp() PHP Developer’s Dictionary IT-SC book 177 Syntax int strcmp(string str1, string str2) Description The strcmp() function returns a negative number if str1 < str2 , a positive number if str1 > str2 , and 0 if str1 = str2 . The strcmp() function is case sensitive. echo strcmp ("abc","ABC");//displays 1 strcspn() Syntax int strcspn(string str1, string str2) Description The strcspn function, which was added in PHP 3.0.2 and PHP 4.0, returns the length of the initial segment of str1 , which does not have any characters found in str2 . echo strcspn("abcdefg","efg");//displays 4 strip_tags() Syntax string strip_tags(string str, [string allowable_tags]) Description The strip_tags() function, which was added in PHP 3.0.8 and PHP 4.0b2, returns a string that is the str string without any HTML or PHP tags in it. The allowable_tags parameter is used to indicate which tags should not be stripped from the str . echo strip_tags ("<TITLE>A Title</TITLE>");//displays A Title PHP Developer’s Dictionary IT-SC book 178 stripcslashes() Syntax string stripcslashes(string str ) Description The stripcslashes() function, which was added in PHP 4.0b2, returns a string with any escaped or "C-slashed" characters removed. C-escaped characters include \\ n, \\ r , and so on. stripslashes() Syntax string stripslashes(string str) Description The stripslashes() function returns a string with all backslashes removed. For example, "\n" becomes "n" , "\\" becomes "\" , and so on. stristr() Syntax string stristr(string haystack, string needle) Description The stristr() function, which was added in PHP 3.0.6 and PHP 4.0, returns a portion of haystack , starting from the first occurrence of needle until the end of haystack . The comparison is case insensitive. If needle is not present in haystack , false is returned. If needle is not a string, it is converted to an integer and it is applied as the ordinal value of a character. The ordinal value is the ASCII value for the number; for instance, 65 = A. echo stristr("abcdEfg","e");//displays Efg PHP Developer’s Dictionary IT-SC book 179 strlen() Syntax int strlen(string str ) Description The strlen() function returns the length of str . echo strlen("123456789");//displays 9 strpos() Syntax int strpos(string haystack, string needle, [int offset] ) Description The strpos() function returns the position of the last occurrence of needle in haystack as a number indicating the offset. If needle is not found, the return value will be false. If needle is a number, it is converted to an integer and applied as the ordinal value of a character. Optionally, the offset parameter enables you to specify from where in the haystack to start searching. However, the position returned is in relation to the beginning of haystack . strrchr() Syntax string strrchr(string haystack, string needle) Description The strrchr() function returns a subset of haystack , which begins at the start of the last occurrence of needle and goes to the end of haystack . If needle isn't found . Description The strip_tags() function, which was added in PHP 3.0.8 and PHP 4.0b2, returns a string that is the str string without any HTML or PHP tags in it. The allowable_tags parameter is used. strcspn(string str1, string str2) Description The strcspn function, which was added in PHP 3.0.2 and PHP 4.0, returns the length of the initial segment of str1 , which does not have any characters. strcasecmp(string str1, string str2) Description The strcasecmp() function, which was added in PHP 3.0.2 and PHP 4.0, returns a negative number if str1 < str2 , a positive number if str2 > str1