Você está na página 1de 25

1.The addcslashes() function returns a string with backslashes in front of the s pecified characters. addcslashes(string,characters) $str = addcslashes("Hello World!

","W"); echo($str); Hello \World! 2. The addslashes() function returns a string with backslashes in front of prede fined characters. The predefined characters are: single quote (') double quote (") backslash (\) NULL addslashes(string) $str = addslashes('What does "yolo" mean?'); echo($str); What does \"yolo\" mean? 3.The chop() function removes whitespaces or other predefined characters from th e right end of a string chop(string,charlist) $str = "Hello World!"; echo $str . "<br>"; echo chop($str,"World!"); Hello World! Hello 4.The chr() function returns a character from the specified ASCII value. The ASCII value can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x. chr(ascii) echo chr(52) . "<br>"; // Decimal value echo chr(052) . "<br>"; // Octal value echo chr(0x52) . "<br>"; // Hex value 4 * R 5. The chunk_split() function splits a string into a series of smaller parts. Note: This function does not alter the original string. chunk_split(string,length,end) $str = "Hello world!"; echo chunk_split($str,1,"."); H.e.l.l.o. .w.o.r.l.d.!. 6. The convert_cyr_string() function converts a string from one Cyrillic charact er-set to another. The supported Cyrillic character-sets are: k - koi8-r w - windows-1251 i - iso8859-5 a - x-cp866 d - x-cp866 m - x-mac-cyrillic Note: This function is binary-safe.

The convert_cyr_string() function converts a string from one Cyrillic characterset to another. The supported Cyrillic character-sets are: k w i a d m koi8-r windows-1251 iso8859-5 x-cp866 x-cp866 x-mac-cyrillic

Note: This function is binary-safe. convert_cyr_string(string,from,to) $str = "Hello world! "; echo $str . "<br>"; echo convert_cyr_string($str,'w','a'); Hello world! Hello world! In this example we convert a string from the character-set "w" (windows-1251) to "a" (x-cp866). 7. The convert_uudecode() function decodes a uuencoded string. This function is often used together with the convert_uuencode() function. convert_uudecode(string) $str = ",2&5L;&\@=V]R;&0A `"; echo convert_uudecode($str); Hello world! 8. The convert_uuencode() function encodes a string using the uuencode algorithm . Note: This function encodes all strings (including binary) into printable charac ters. This will fix any problems with obscure binary data when storing in a data base or transmit data over a network. Remember to use the convert_uudecode() fun ction before using the data again. Note: Uuencoded data is about 35% larger than the original. convert_uuencode(string) $str = "Hello world!"; echo convert_uuencode($str); ,2&5L;&\@=V]R;&0A ` 9. The count_chars() function returns information about characters used in a str ing (for example, how many times an ASCII character occurs in a string, or which characters that have been used or not been used in a string). Syntax count_chars(string,mode) $str = "Hello World!"; echo count_chars($str,3); The parameter "mode 3" will return a string with all the different characters us ed. In this example, the characters used in "Hello World!" are: !HWdelor 10. The crc32() function calculates a 32-bit CRC (cyclic redundancy checksum) fo

r a string. This function can be used to validate data integrity. Tip: To ensure that you get the correct string representation from the crc32() f unction, you'll need to use the %u formatter of the printf() or sprintf() functi on. If the %u formatter is not used, the result may display in incorrect and neg ative numbers. Syntax crc32(string) $str = crc32("Hello World!"); printf("%u\n",$str); 472456355 11. The crypt() function returns a string encrypted using DES, Blowfish, or MD5 algorithms. This function behaves different on different operating systems, some operating s ystems supports more than one type of encryption. PHP checks what algorithms are available and what algorithms to use when it is installed. The exact algorithm depends on the format and length of the salt parameter. Salt s help make the encryption more secure by increasing the number of encrypted str ings that can be generated for one specific string with one specific encryption method. There are some constants that are used together with the crypt() function. The v alue of these constants are set by PHP when it is installed. Syntax crypt(str,salt) 12. The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe. Syntax explode(separator,string,limit) $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. ) 13. The fprintf() function writes a formatted string to a specified output strea m (example: file or database). The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works "step-by-step". At the first % sign, arg1 is inserte d, at the second % sign, arg2 is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: printf(), sprintf(), vprintf(), vsprintf() and vfprintf( ) Syntax fprintf(stream,format,arg1,arg2,arg++) $number = 9; $str = "Beijing"; $file = fopen("test.txt","w");

echo fprintf($file,"There are %u million bicycles in %s.",$number,$str); The output of the code above will be: 40 The following text will be written to the file "test.txt": There are 9 million bicycles in Beijing. 14. The get_html_translation_table() function returns the translation table used by the htmlentities() and htmlspecialchars() functions. Tip: Some characters can be encoded several ways. The get_html_translation_table () function returns the most common encoding. Syntax get_html_translation_table(function,flags,character-set) print_r (get_html_translation_table()); // HTML_SPECIALCHARS is default. Array ( ["] => " [&] => & [<] => < [>] => > ) 15. The html_entity_decode() function converts HTML entities to characters. The html_entity_decode() function is the opposite of htmlentities(). Syntax html_entity_decode(string,flags,character-set) $str = "&lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;"; echo html_entity_decode($str); ?> The HTML output of the code above will be (View Source): <!DOCTYPE html> <html> <body> <? W3S?h????> </body> </html> The browser output of the code above will be: <? W3S?h????> $str = "&lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;"; echo html_entity_decode($str); ?> The HTML output of the code above will be (View Source): <!DOCTYPE html> <html> <body> <? W3S?h????> </body> </html> The browser output of the code above will be: <? W3S?h????> 16. The htmlentities() function converts characters to HTML entities. Tip: To convert HTML entities back to characters, use the html_entity_decode() f unction. Tip: Use the get_html_translation_table() function to return the translation tab le used by htmlentities(). Syntax htmlentities(string,flags,character-set,double_encode) $str = "< W3Sh>"; echo htmlentities($str); ?>

<p>Converting characters into entities are often used to prevent browsers from u sing it as an HTML element. This can be especially useful to prevent code from r unning when users have access to display input on your homepage.</p> Converting characters into entities are often used to prevent browsers from usin g it as an HTML element. This can be especially useful to prevent code from runn ing when users have access to display input on your homepage. 17. The htmlspecialchars_decode() function converts some predefined HTML entitie s to characters. HTML entities that will be decoded are: &amp; becomes & (ampersand) &quot; becomes " (double quote) &#039; becomes ' (single quote) &lt; becomes < (less than) &gt; becomes > (greater than) The htmlspecialchars_decode() function is the opposite of htmlspecialchars(). Syntax htmlspecialchars_decode(string,flags) $str = "This is some &lt;b&gt;bold&lt;/b&gt; text."; echo htmlspecialchars_decode($str); ?> The HTML output of the code above will be (View Source): <!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html> The browser output of the code above will be: This is some bold text. 18. The htmlspecialchars() function converts some predefined characters to HTML entities. The predefined characters are: & (ampersand) becomes &amp; " (double quote) becomes &quot; ' (single quote) becomes &#039; < (less than) becomes &lt; > (greater than) becomes &gt; Tip: To convert special HTML entities back to characters, use the htmlspecialcha rs_decode() function. Syntax htmlspecialchars(string,flags,character-set,double_encode) $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?> <p>Converting < and > into entities are often used to prevent browsers from usin g it as an HTML element. This can be especially useful to prevent code from runn ing when users have access to display input on your homepage.</p> This is some <b>bold</b> text.

Converting < and > into entities are often used to prevent browsers from using i t as an HTML element. This can be especially useful to prevent code from running when users have access to display input on your homepage. 19. The implode() function returns a string from the elements of an array. Note: The implode() function accept its parameters in either order. However, for consistency with explode(), you should use the documented order of arguments. Note: The separator parameter of implode() is optional. However, it is recommend ed to always use two parameters for backwards compatibility. Note: This function is binary-safe. Syntax implode(separator,array) $arr = array('Hello','World!','Beautiful','Day!'); echo implode(" ",$arr); Hello World! Beautiful Day! 20. The join() function returns a string from the elements of an array. The join() function is an alias of the implode() function. Note: The join() function accept its parameters in either order. However, for co nsistency with explode(), you should use the documented order of arguments. Note: The separator parameter of join() is optional. However, it is recommended to always use two parameters for backwards compatibility. Syntax join(separator,array) $arr = array('Hello','World!','Beautiful','Day!'); echo join(" ",$arr); Hello World! Beautiful Day! 21. The lcfirst() function converts the first character of a string to lowercase . Related functions: ucfirst() - converts the first character of a string to uppercase ucwords() - converts the first character of each word in a string to uppercase strtoupper() - converts a string to uppercase strtolower() - converts a string to lowercase Syntax lcfirst(string) echo lcfirst("Hello world!"); hello world! 22. The levenshtein() function returns the Levenshtein distance between two stri ngs. The Levenshtein distance is the number of characters you have to replace, insert or delete to transform string1 into string2. By default, PHP gives each operation (replace, insert, and delete) equal weight. However, you can define the cost of each operation by setting the optional inse rt, replace, and delete parameters. Note: The levenshtein() function is not case-sensitive. Note: The levenshtein() function is faster than the similar_text() function. How ever, similar_text() will give you a more accurate result with less modification

s needed. Syntax levenshtein(string1,string2,insert,replace,delete) echo levenshtein("Hello World","ello World"); echo "<br>"; echo levenshtein("Hello World","ello World",10,20,30); 1 30 23. The localeconv() function returns an array containing local numeric and mone tary formatting information. The localeconv() function will return the following array elements: [decimal_point] - Decimal point character [thousands_sep] - Thousands separator [int_curr_symbol] - Currency symbol (example: USD) [currency_symbol] - Currency symbol (example: $) [mon_decimal_point] - Monetary decimal point character [mon_thousands_sep] - Monetary thousands separator [positive_sign] - Positive value character [negative_sign] - Negative value character [int_frac_digits] - International fractional digits [frac_digits] - Local fractional digits [p_cs_precedes] - True (1) if currency symbol is placed in front of a positive v alue, False (0) if it is placed behind [p_sep_by_space] - True (1) if there is a spaces between the currency symbol and a positive value, False (0) otherwise [n_cs_precedes] - True (1) if currency symbol is placed in front of a negative v alue, False (0) if it is placed behind [n_sep_by_space] - True (1) if there is a spaces between the currency symbol and a negative value, False (0) otherwise [p_sign_posn] - Formatting options: 0 - Parentheses surround the quantity and currency symbol 1 - The + sign is placed in front of the quantity and currency symbol 2 - The + sign is placed after the quantity and currency symbol 3 - The + sign is placed immediately in front of the currency symbol 4 - The + sign is placed immediately after the currency symbol [n_sign_posn] - Formatting options: 0 - Parentheses surround the quantity and currency symbol 1 - The - sign is placed in front of the quantity and currency symbol 2 - The - sign is placed after the quantity and currency symbol 3 - The - sign is placed immediately in front of the currency symbol 4 - The - sign is placed immediately after the currency symbol [grouping] - Array displaying how numbers are grouped (example: 3 indicates 1 00 0 000) [mon_grouping] - Array displaying how monetary numbers are grouped (example: 2 i ndicates 1 00 00 00) Tip: To define locale settings, see the setlocale() function. Tip: To view all available language codes, go to our Language code reference. Syntax localeconv() setlocale(LC_ALL,"US"); $locale_info = localeconv(); print_r($locale_info); Array ( [decimal_point] => . [thousands_sep] => , [int_curr_symbol] => USD [curr ency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_si

gn] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_prec edes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_s ign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping ] => Array ( [0] => 3 ) ) 24. The ltrim() function removes whitespace or other predefined characters from the left side of a string. Related functions: rtrim() - Removes whitespace or other predefined characters from the right side of a string trim() - Removes whitespace or other predefined characters from both sides of a string Syntax ltrim(string,charlist) $str = "Hello World!"; echo $str . "<br>"; echo ltrim($str,"Hello"); Hello World! World! 25. The md5() function calculates the MD5 hash of a string. The md5() function uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm . From RFC 1321 - The MD5 Message-Digest Algorithm: "The MD5 message-digest algori thm takes as input a message of arbitrary length and produces as output a 128-bi t "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public -key cryptosystem such as RSA." To calculate the MD5 hash of a file, use the md5_file() function. Syntax md5(string,raw) $str = "Hello"; echo md5($str); 8b1a9953c4611296a827abf8c47804d7 26. The md5_file() function calculates the MD5 hash of a file. The md5_file() function uses the RSA Data Security, Inc. MD5 Message-Digest Algo rithm. From RFC 1321 - The MD5 Message-Digest Algorithm: "The MD5 message-digest algori thm takes as input a message of arbitrary length and produces as output a 128-bi t "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public -key cryptosystem such as RSA." To calculate the MD5 hash of a string, use the md5() function. Syntax md5_file(file,raw) $filename = "test.txt"; $md5file = md5_file($filename); echo $md5file;

The output of the code above will be: d41d8cd98f00b204e9800998ecf8427e 27. The metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if said by an English speaking pe rson. The metaphone() function can be used for spelling applications. Note: The metaphone() function creates the same key for similar sounding words. Note: The generated metaphone keys vary in length. Tip: metaphone() is more accurate than the soundex() function, because metaphone () knows the basic rules of English pronunciation. Syntax metaphone(string,length) echo metaphone("World"); WRLT 28. The money_format() function returns a string formatted as a currency string. This function inserts a formatted number where there is a percent (%) sign in th e main string. Note: The money_format() function does not work on Windows platforms. Tip: This function is often used together with the setlocale() function. Tip: To view all available language codes, go to our Language code reference. Syntax money_format(string,number) $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $number); The output of the code above will be: The price is USD 1,234.56 29. The nl_langinfo() function returns specific local information. Note: This function does not work on Windows platforms. Tip: Unlike the localeconv() function, which returns all local formatting inform ation, the nl_langinfo() function returns specific information. Syntax nl_langinfo(element) 30. The nl2br() function inserts HTML line breaks (<br> or <br />) in front of e ach newline (\n) in a string. Syntax nl2br(string,xhtml) echo nl2br("One line.\nAnother line."); One line. Another line. 31. The number_format() function formats a number with grouped thousands. Note: This function supports one, two, or four parameters (not three). Syntax number_format(number,decimals,decimalpoint,separator) echo number_format("1000000")."<br>"; echo number_format("1000000",2)."<br>"; echo number_format("1000000",2,",",".");

1,000,000 1,000,000.00 1.000.000,00 32. The ord() function returns the ASCII value of the first character of a strin g. Syntax ord(string) echo ord("h")."<br>"; echo ord("hello")."<br>"; 104 104 33. The parse_str() function parses a query string into variables. Note: If the array parameter is not set, variables set by this function will ove rwrite existing variables of the same name. Note: The magic_quotes_gpc setting in the php.ini file affects the output of thi s function. If enabled, the variables are converted by addslashes() before parse d by parse_str(). Syntax parse_str(string,array) parse_str("name=Peter&age=43"); echo $name."<br>"; echo $age; Peter 43 34. The printf() function outputs a formatted string. The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works "step-by-step". At the first % sign, arg1 is inserte d, at the second % sign, arg2 is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: sprintf(), vprintf(), vsprintf(), fprintf() and vfprintf () Syntax printf(format,arg1,arg2,arg++) $number = 9; $str = "Beijing"; printf("There are %u million bicycles in %s.",$number,$str); There are 9 million bicycles in Beijing. 35. The quoted_printable_decode() function decodes a quoted-printable string to an 8-bit ASCII string. Tip: Data encoded in quoted-printable are unlikely to be modified by mail transp ort. A text which is entirely US-ASCII may be encoded in quoted-printable to ens ure the integrity of the data should the message pass through a character-transl ating, or line-wrapping gateway. Syntax quoted_printable_decode(string) $str = "Hello=0Aworld.";

echo quoted_printable_decode($str); Hello world. 36. The quoted_printable_encode() function converts an 8-bit string to a quotedprintable string. Tip: Data encoded in quoted-printable are unlikely to be modified by mail transp ort. A text which is entirely US-ASCII may be encoded in quoted-printable to ens ure the integrity of the data should the message pass through a character-transl ating, or line-wrapping gateway. Syntax quoted_printable_encode(string) 37. The quoted_printable_encode() function converts an 8-bit string to a quotedprintable string. Tip: Data encoded in quoted-printable are unlikely to be modified by mail transp ort. A text which is entirely US-ASCII may be encoded in quoted-printable to ens ure the integrity of the data should the message pass through a character-transl ating, or line-wrapping gateway. Syntax quoted_printable_encode(string) $str = "Hello world. (can you hear me?)"; echo quotemeta($str); Hello world\. \(can you hear me\?\) 38. The rtrim() function removes whitespace or other predefined characters from the right side of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side o f a string trim() - Removes whitespace or other predefined characters from both sides of a string Syntaxrtrim(string,charlist) $str = "Hello World!"; echo $str . "<br>"; echo rtrim($str,"World!"); Hello World! Hello 39. The setlocale() function sets locale information. Locale information is language, monetary, time and other information specific fo r a geographical area. Note: The setlocale() function changes the locale only for the current script. Tip: The locale information can be set to system default with setlocale(LC_ALL,N ULL) Tip: To get numeric formatting information, see the localeconv() function. Syntax setlocale(constant,location) echo setlocale(LC_ALL,"US"); echo "<br>"; echo setlocale(LC_ALL,NULL); English_United States.1252 English_United States.1252

40. The sha1() function calculates the SHA-1 hash of a string. The sha1() function uses the US Secure Hash Algorithm 1. From RFC 3174 - The US Secure Hash Algorithm 1: "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficienc y of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." Tip: To calculate the SHA-1 hash of a file, use the sha1_file() function. Syntax sha1(string,raw) $str = "Hello"; echo sha1($str); f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 41. The sha1_file() function calculates the SHA-1 hash of a file. The sha1_file() function uses the US Secure Hash Algorithm 1. From RFC 3174 - The US Secure Hash Algorithm 1: "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficienc y of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." This function returns the calculated SHA-1 hash on success, or FALSE on failure. Syntax sha1_file(file,raw) $filename = "test.txt"; $sha1file = sha1_file($filename); echo $sha1file; ?> The output of the code above will be: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d 42. The similar_text() function calculates the similarity between two strings. It can also calculate the similarity of the two strings in percent. Note: The levenshtein() function is faster than the similar_text() function. How ever, the similar_text() function will give you a more accurate result with less modifications needed. Syntax similar_text(string1,string2,percent) echo similar_text("Hello World","Hello Peter"); 7 43. The soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric string that represent Englis h pronunciation of a word. The soundex() function can be used for spelling applications. Note: The soundex() function creates the same key for similar sounding words. Tip: metaphone() is more accurate than soundex(), because metaphone() knows the basic rules of English pronunciation. Syntax soundex(string)

$str = "Hello"; echo soundex($str); H400 44. The sprintf() function writes a formatted string to a variable. The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works "step-by-step". At the first % sign, arg1 is inserte d, at the second % sign, arg2 is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: printf(), vprintf(), vsprintf(), fprintf() and vfprintf( ) Syntax sprintf(format,arg1,arg2,arg++) $number = 9; $str = "Beijing"; $txt = sprintf("There are %u million bicycles in %s.",$number,$str); echo $txt; There are 9 million bicycles in Beijing. 45. The sscanf() function parses input from a string according to a specified fo rmat. The sscanf() function parses a string into variables based on the format s tring. If only two parameters are passed to this function, the data will be returned as an array. Otherwise, if optional parameters are passed, the data parsed are sto red in them. If there are more specifiers than variables to contain them, an err or occurs. However, if there are less specifiers than variables, the extra varia bles contain NULL. Related functions: printf() - outputs a formatted string sprintf() - writes a formatted string to a variable Syntax sscanf(string,format,arg1,arg2,arg++) $str = "age:30 weight:60kg"; sscanf($str,"age:%d weight:%dkg",$age,$weight); // show types and values var_dump($age,$weight); int(30) int(60) 45. The str_getcsv() function parses a string for fields in CSV format and retur ns an array containing the fields read. Syntax str_getcsv(string,separator,enclosure,escape) 46. The str_ireplace() function replaces some characters with some other charact ers in a string. This function works by the following rules: If the string to be searched is an array, it returns an array If the string to be searched is an array, find and replace is performed with eve ry array element If both find and replace are arrays, and replace has fewer elements than find, a n empty string will be used as replace

If find is an array every find value Note: This function rm a case-sensitive Note: This function

and replace is a string, the replace string will be used for is case-insensitive. Use the str_replace() function to perfo search. is binary-safe.

Syntax str_ireplace(find,replace,string,count) echo str_ireplace("WORLD","Peter","Hello world!"); <p>In this example, we search for the string "Hello World!", find the value "WOR LD" and then replace the value with "Peter".</p> Hello Peter! In this example, we search for the string "Hello World!", find the value "WORLD" and then replace the value with "Peter". 47. The str_pad() function pads a string to a new length. Syntax str_pad(string,length,pad_string,pad_type) $str = "Hello World"; echo str_pad($str,20,"."); Hello World......... 48. Definition and Usage The str_repeat() function repeats a string a specified number of times. Syntax str_repeat(string,repeat) echo str_repeat(".",13); ............. 49. The str_replace() function replaces some characters with some other characte rs in a string. This function works by the following rules: If the string to be searched is an array, it returns an array If the string to be searched is an array, find and replace is performed with eve ry array element If both find and replace are arrays, and replace has fewer elements than find, a n empty string will be used as replace If find is an array and replace is a string, the replace string will be used for every find value Note: This function is case-sensitive. Use the str_ireplace() function to perfor m a case-insensitive search. Note: This function is binary-safe. Syntax str_replace(find,replace,string,count) echo str_replace("world","Peter","Hello world!"); <p>In this example, we search for the string "Hello World!", find the value "wor ld" and then replace the value with "Peter".</p> Hello Peter! In this example, we search for the string "Hello World!", find the value "world"

and then replace the value with "Peter". 50. The str_rot13() function performs the ROT13 encoding on a string. The ROT13 encoding shifts every letter 13 places in the alphabet. Numeric and no n-alphabetical characters remains untouched. Tip: Encoding and decoding are done by the same function. If you pass an encoded string as argument, the original string will be returned. Syntax str_rot13(string) echo str_rot13("Hello World"); echo "<br>"; echo str_rot13("Uryyb Jbeyq"); Uryyb Jbeyq Hello World 51. The str_shuffle() function randomly shuffles all the characters of a string. Syntax str_shuffle(string) echo str_shuffle("Hello World"); ?> <p>Try to refresh the page. This function will randomly shuffle all characters e ach time.</p> echo str_shuffle("Hello World"); ?> <p>Try to refresh the page. This function will randomly shuffle all characters e ach time.</p> 52. The str_split() function splits a string into an array. Syntax str_split(string,length) print_r(str_split("Hello")); Array ( [0] => H [1] => e [2] => l [3] => l [4] => o ) 53. The str_word_count() function counts the number of words in a string. Syntax str_word_count(string,return,char) echo str_word_count("Hello world!"); 2 54. The strcasecmp() function compares two strings. Tip: The strcasecmp() function is binary-safe and case-insensitive. Tip: This function is similar to the strncasecmp() function, with the difference that you can specify the number of characters from each string to be used in th e comparison with strncasecmp(). Syntax strcasecmp(string1,string2) echo strcasecmp("Hello world!","HELLO WORLD!"); 0 If this function returns 0, the two strings are equal. 55. The strchr() function searches for the first occurrence of a string inside a nother string.

This function is an alias of the strstr() function. Note: This function is binary-safe. Note: This function is case-sensitive. For a case-insensitive search, use strist r() function. Syntax strchr(string,search,before_search); echo strchr("Hello world!","world"); world! 56. The strcmp() function compares two strings. Note: The strcmp() function is binary-safe and case-sensitive. Tip: This function is similar to the strncmp() function, with the difference tha t you can specify the number of characters from each string to be used in the co mparison with strncmp(). Syntax strcmp(string1,string2) echo strcmp("Hello world!","Hello world!"); 0 If this function returns 0, the two strings are equal. 57. The strcoll() function compares two strings. The comparison of the strings may vary depending on the locale settings (A<a or A>a). Note: The strcoll() is case-sensitive but not binary-safe. Note: If the current locale is C or POSIX, this function works the same way as s trcmp(). Syntax strcoll(string1,string2) setlocale (LC_COLLATE, 'NL'); echo strcoll("Hello World!","Hello World!"); echo "<br>"; setlocale (LC_COLLATE, 'en_US'); echo strcoll("Hello World!","Hello World!"); ?> <p>If this function returns 0, the two strings are equal.</p> 0 0 If this function returns 0, the two strings are equal. 58. The strcspn() function returns the number of characters (including whitespac es) found in a string before any part of the specified characters are found. Tip: Use the strspn() function to the number of characters found in the string t hat contains only characters from a specified character list. Note: This function is binary-safe. Syntax strcspn(string,char,start,length) echo strcspn("Hello world!","w");

6 59. The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow p arameter. Note: This function is binary-safe. Syntax strip_tags(string,allow) echo strip_tags("Hello <b>world!</b>"); ?> <p>This function strips a string from HTML, XML, and PHP tags. In this example, the <b> tag gets stripped.</p> Hello world! This function strips a string from HTML, XML, and PHP tags. In this example, the <b> tag gets stripped. 60. The stripcslashes() function removes backslashes added by the addcslashes() function. Tip: This function can be used to clean up data retrieved from a database or fro m an HTML form. Syntax stripcslashes(string) echo stripslashes("Hello \World!"); Hello World! 61. The stripslashes() function removes backslashes added by the addslashes() fu nction. Tip: This function can be used to clean up data retrieved from a database or fro m an HTML form. Syntax stripslashes(string) echo stripslashes("Who\'s Peter Griffin?"); Who's Peter Griffin? 62. The stripos() function finds the position of the first occurrence of a strin g inside another string. Note: The stripos() function is case-insensitive. Note: This function is binary-safe. Related functions: strripos() - Finds the position of the last occurrence of a string inside anothe r string (case-insensitive) strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive) strrpos() - Finds the position of the last occurrence of a string inside another string (case-sensitive) Syntax stripos(string,find,start)

echo stripos("I love php, I love php too!","PHP"); 7 63. The stristr() function searches for the first occurrence of a string inside another string. Note: This function is binary-safe. Note: This function is case-insensitive. For a case-sensitive search, use strstr () function. Syntax stristr(string,search,before_search) echo stristr("Hello world!","WORLD"); world! 64. The strlen() function returns the length of a string. Syntax strlen(string) echo strlen("Hello"); 5 65. The strnatcasecmp() function compares two strings using a "natural" algorith m. In a natural algorithm, the number 2 is less than the number 10. In computer sor ting, 10 is less than 2, because the first number in "10" is less than 2. Note: The strnatcasecmp() is case-insensitive.

Syntax strnatcasecmp(string1,string2) echo strnatcasecmp("2Hello world!","10Hello WORLD!"); echo "<br>"; echo strnatcasecmp("10Hello world!","2Hello WORLD!"); -1 1 66. The strnatcmp() function compares two strings using a "natural" algorithm. In a natural algorithm, the number 2 is less than the number 10. In computer sor ting, 10 is less than 2, because the first number in "10" is less than 2. Note: This function is case-sensitive. Syntax strnatcmp(string1,string2) echo strnatcmp("2Hello world!","10Hello world!"); echo "<br>"; echo strnatcmp("10Hello world!","2Hello world!"); -1 1 67. The strncasecmp() function compares two strings. Note: The strncasecmp() is binary-safe and case-insensitive.

Tip: This function is similar to the strcasecmp() function, except that strcasec mp() does not have the length parameter. Syntax strncasecmp(string1,string2,length) echo strncasecmp("Hello world!","hello earth!",6); 0 68. The strncmp() function compares two strings. Note: The strncmp() is binary-safe and case-sensitive. Tip: This function is similar to the strcmp() function, except that strcmp() doe s not have the length parameter. Syntax strncmp(string1,string2,length) echo strncmp("Hello world!","Hello earth!",6); 0 69. The strpbrk() function searches a string for any of the specified characters . Note: This function is case-sensitive. This function returns the rest of the string from where it found the first occur rence of a specified character, otherwise it returns FALSE. Syntax strpbrk(string,charlist) echo strpbrk("Hello world!","oe"); ?> <p>"e" is the first occurrence of the specified characters. This function will t herefore output "ello world!", because it returns the rest of the string from wh ere it found the first occurrence of "e".</p> ello world! "e" is the first occurrence of the specified characters. This function will ther efore output "ello world!", because it returns the rest of the string from where it found the first occurrence of "e". 70. The strpos() function finds the position of the first occurrence of a string inside another string. Note: The strpos() function is case-sensitive. Note: This function is binary-safe. Related functions: strrpos() - Finds the position of the last occurrence of a string inside another string (case-sensitive) stripos() - Finds the position of the first occurrence of a string inside anothe r string (case-insensitive) strripos() - Finds the position of the last occurrence of a string inside anothe r string (case-insensitive) Syntax strpos(string,find,start) echo strpos("I love php, I love php too!","php"); 7

71. The strrchr() function finds the position of the last occurrence of a string within another string, and returns all characters from this position to the end of the string. Note: This function is binary-safe. Syntax strrchr(string,char) echo strrchr("Hello world!","world"); world! 72. The strrev() function reverses a string. Syntax strrev(string) echo strrev("Hello World!"); !dlroW olleH 73. The strripos() function finds the position of the last occurrence of a strin g inside another string. Note: The strripos() function is case-insensitive. Related functions: stripos() - Finds the position of the first occurrence of a string inside anothe r string (case-insensitive) strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive) strrpos() - Finds the position of the last occurrence of a string inside another string (case-sensitive) Syntax strripos(string,find,start) echo strripos("I love php, I love php too!","PHP"); 19 74. The strrpos() function finds the position of the last occurrence of a string inside another string. Note: The strrpos() function is case-sensitive. Related functions: strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive) stripos() - Finds the position of the first occurrence of a string inside anothe r string (case-insensitive) strripos() - Finds the position of the last occurrence of a string inside anothe r string (case-insensitive) Syntax strrpos(string,find,start) echo strrpos("I love php, I love php too!","php"); 19

75. The strspn() function returns the number of characters found in the string t hat contains only characters from the charlist parameter. Tip: Use the strcspn() function to return the number of characters found in a st ring before any part of the specified characters are found. Note: This function is binary-safe. Syntax strspn(string,charlist,start,length) echo strspn("Hello world!","kHlleo"); 5 76. The strstr() function searches for the first occurrence of a string inside a nother string. Note: This function is binary-safe. Note: This function is case-sensitive. For a case-insensitive search, use strist r() function. Syntax strstr(string,search,before_search) echo strstr("Hello world!","world"); world! 77. The strrev() function reverses a string. Syntax strrev(string) echo strrev("Hello World!"); !dlroW olleH 78. The strripos() function finds the position of the last occurrence of a strin g inside another string. Note: The strripos() function is case-insensitive. Related functions: stripos() - Finds the position of the first occurrence of a string inside anothe r string (case-insensitive) strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive) strrpos() - Finds the position of the last occurrence of a string inside another string (case-sensitive) Syntax strripos(string,find,start) echo strripos("I love php, I love php too!","PHP"); 19 79. The strrpos() function finds the position of the last occurrence of a string inside another string. Note: The strrpos() function is case-sensitive. Related functions: strpos() - Finds the position of the first occurrence of a string inside another

string (case-sensitive) stripos() - Finds the position of the first occurrence of a string inside anothe r string (case-insensitive) strripos() - Finds the position of the last occurrence of a string inside anothe r string (case-insensitive) Syntax strrpos(string,find,start) echo strrpos("I love php, I love php too!","php"); 19 80. The strspn() function returns the number of characters found in the string t hat contains only characters from the charlist parameter. Tip: Use the strcspn() function to return the number of characters found in a st ring before any part of the specified characters are found. Note: This function is binary-safe. Syntax strspn(string,charlist,start,length) echo strspn("Hello world!","kHlleo"); 5 81. The strstr() function searches for the first occurrence of a string inside a nother string. Note: This function is binary-safe. Note: This function is case-sensitive. For a case-insensitive search, use strist r() function. Syntax strstr(string,search,before_search) echo strstr("Hello world!","world"); world! 82. The substr() function returns a part of a string. Note: If the start parameter is a negative number and length is less than or equ al to start, length becomes 0. Syntax substr(string,start,length) echo substr("Hello world",6); world 83. The substr_compare() function compares two strings from a specified start po sition. Tip: This function is binary-safe and optionally case-sensitive. Syntax substr_compare(string1,string2,startpos,length,case) echo substr_compare("Hello world","Hello world",0); <p>If this function returns 0, the two strings are equal.</p> 0

If this function returns 0, the two strings are equal. 84. The substr_count() function counts the number of times a substring occurs in a string. Note: The substring Note: This function Note: This function arameter is greater is case-sensitive. does not count overlapped substrings (see example 2). generates a warning if the start parameter plus the length p than the string length (see example 3).

Syntax substr_count(string,substring,start,length) echo substr_count("Hello world. The world is nice","world"); 2 85. The substr_replace() function replaces a part of a string with another strin g. Note: If the start parameter is a negative number and length is less than or equ al to start, length becomes 0. Note: This function is binary-safe. Syntax substr_replace(string,replacement,start,length) echo substr_replace("Hello","world",0); // 0 will start replacing at the first c haracter in the string world 86. The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side o f a string rtrim() - Removes whitespace or other predefined characters from the right side of a string Syntax trim(string,charlist) $str = "Hello World!"; echo $str . "<br>"; echo trim($str,"Hed!"); Hello World! llo Worl 87. The ucfirst() function converts the first character of a string to uppercase . Related functions: lcfirst() - converts the first character of a string to lowercase ucwords() - converts the first character of each word in a string to uppercase strtoupper() - converts a string to uppercase strtolower() - converts a string to lowercase Syntax ucfirst(string) echo ucfirst("hello world!");

Hello world! 88. The ucwords() function converts the first character of each word in a string to uppercase. Note: This function is binary-safe. Related functions: ucfirst() - converts the first character of a string to uppercase lcfirst() - converts the first character of a string to lowercase strtoupper() - converts a string to uppercase strtolower() - converts a string to lowercase Syntax ucwords(string) echo ucwords("hello world"); Hello World 89. The vfprintf() function writes a formatted string to a specified output stre am (example: file or database). Unlike fprintf(), the arguments in vfprintf(), are placed in an array. The array elements will be inserted at the percent (%) signs in the main string. This fun ction works "step-by-step". At the first % sign, the first array element is inse rted, at the second % sign, the second array element is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: fprintf(), printf(), sprintf(), vprintf() and vsprintf() . Syntax vfprintf(stream,format,argarray) $number = 9; $str = "Beijing"; $file = fopen("test.txt","w"); echo vfprintf($file,"There are %u million bicycles in %s.",array($number,$str)); ?> The output of the code above will be: 40 The following text will be written to the file "test.txt": There are 9 million bicycles in Beijing. 90. The vprintf() function outputs a formatted string. Unlike printf(), the arguments in vprintf(), are placed in an array. The array e lements will be inserted at the percent (%) signs in the main string. This funct ion works "step-by-step". At the first % sign, the first array element is insert ed, at the second % sign, the second array element is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: sprintf(), printf(), vsprintf(), fprintf() and vfprintf( ) Syntax vprintf(format,argarray)

$number = 9; $str = "Beijing"; vprintf("There are %u million bicycles in %s.",array($number,$str)); There are 9 million bicycles in Beijing. 91. The vsprintf() function writes a formatted string to a variable. Unlike sprintf(), the arguments in vsprintf(), are placed in an array. The array elements will be inserted at the percent (%) signs in the main string. This fun ction works "step-by-step". At the first % sign, the first array element is inse rted, at the second % sign, the second array element is inserted, etc. Note: If there are more % signs than arguments, you must use placeholders. A pla ceholder is inserted after the % sign, and consists of the argument- number and "\$". See example two. Tip: Related functions: fprintf(), vfprintf(), printf(), sprintf() and vprintf() . Syntax vsprintf(format,argarray) $number = 9; $str = "Beijing"; $txt = vsprintf("There are %u million bicycles in %s.",array($number,$str)); echo $txt; There are 9 million bicycles in Beijing. 92.The wordwrap() function wraps a string into new lines when it reaches a speci fic length. Note: This function may leave white spaces at the beginning of a line. Syntax wordwrap(string,width,break,cut) $str = "An example of a long word is: Supercalifragulistic"; echo wordwrap($str,15,"<br>\n"); An example of a long word is: Supercalifragulistic The end