{"id":218,"date":"2019-11-15T05:35:26","date_gmt":"2019-11-15T05:35:26","guid":{"rendered":"https:\/\/tutorialio.com\/?p=218"},"modified":"2019-11-15T05:35:26","modified_gmt":"2019-11-15T05:35:26","slug":"php-string-functions","status":"publish","type":"post","link":"https:\/\/hellonitish.com\/blog\/php-string-functions\/","title":{"rendered":"PHP String Functions (All on One Page)"},"content":{"rendered":"<p><a href=\"#addcslashes\">addcslashes()<\/a> \u2014 Quote string with slashes in a C style<\/p>\n<p><a href=\"#addslashes\">addslashes()<\/a> \u2014 Quote string with slashes<\/p>\n<p><a href=\"#bin2hex\">bin2hex()<\/a> \u2014 Convert binary data into hexadecimal representation<\/p>\n<p><a href=\"#chop\">chop()<\/a> \u2014 Alias of rtrim<\/p>\n<p><a href=\"#chr\">chr()<\/a> \u2014 Generate a single-byte string from a number<\/p>\n<p><a href=\"#chunk_split\">chunk_split()<\/a> \u2014 Split a string into smaller chunks<\/p>\n<p><a href=\"#convert_cyr_string\">convert_cyr_string()<\/a> \u2014 Convert from one Cyrillic character set to another<\/p>\n<p><a href=\"#convert_uudecode\">convert_uudecode()<\/a> \u2014 Decode a uuencoded string<\/p>\n<p><a href=\"#convert_uuencode\">convert_uuencode()<\/a> \u2014 Uuencode a string<\/p>\n<p><a href=\"#count_chars\">count_chars()<\/a> \u2014 Return information about characters used in a string<\/p>\n<p><a href=\"#crc32\">crc32()<\/a> \u2014 Calculates the crc32 polynomial of a string<\/p>\n<p><a href=\"#crypt\">crypt()<\/a> \u2014 One-way string hashing<\/p>\n<p><a href=\"#echo\">echo()<\/a> \u2014 Output one or more strings<\/p>\n<p><a href=\"#explode\">explode()<\/a> \u2014 Split a string by a string<\/p>\n<p><a href=\"#fprintf\">fprintf()<\/a> \u2014 Write a formatted string to a stream<\/p>\n<p><a href=\"#get_html_translation_table\">get_html_translation_table()<\/a> \u2014 Returns the translation table used by htmlspecialchars and htmlentities<\/p>\n<p><a href=\"#hebrev\">hebrev()<\/a> \u2014 Convert logical Hebrew text to visual text<\/p>\n<p><a href=\"#hebrevc\">hebrevc()<\/a> \u2014 Convert logical Hebrew text to visual text with newline conversion<\/p>\n<p><a href=\"#hex2bin\">hex2bin()<\/a> \u2014 Decodes a hexadecimally encoded binary string<\/p>\n<p><a href=\"#html_entity_decode\">html_entity_decode()<\/a> \u2014 Convert HTML entities to their corresponding characters<\/p>\n<p><a href=\"#htmlentities\">htmlentities()<\/a> \u2014 Convert all applicable characters to HTML entities<\/p>\n<p><a href=\"#htmlspecialchars_decode\">htmlspecialchars_decode()<\/a> \u2014 Convert special HTML entities back to characters<\/p>\n<p><a href=\"#htmlspecialchars\">htmlspecialchars()<\/a> \u2014 Convert special characters to HTML entities<\/p>\n<p><a href=\"#implode\">implode()<\/a> \u2014 Join array elements with a string<\/p>\n<p><a href=\"#join\">join()<\/a> \u2014 Alias of implode<\/p>\n<p><a href=\"#lcfirst\">lcfirst()<\/a> \u2014 Make a string&#8217;s first character lowercase<\/p>\n<p><a href=\"#levenshtein\">levenshtein()<\/a> \u2014 Calculate Levenshtein distance between two strings<\/p>\n<p><a href=\"#localeconv\">localeconv()<\/a> \u2014 Get numeric formatting information<\/p>\n<p><a href=\"#ltrim\">ltrim()<\/a> \u2014 Strip whitespace (or other characters) from the beginning of a string<\/p>\n<p><a href=\"#md5_file\">md5_file()<\/a> \u2014 Calculates the md5 hash of a given file<\/p>\n<p><a href=\"#md5\">md5()<\/a> \u2014 Calculate the md5 hash of a string<\/p>\n<p><a href=\"#metaphone\">metaphone()<\/a> \u2014 Calculate the metaphone key of a string<\/p>\n<p><a href=\"#money_format\">money_format()<\/a> \u2014 Formats a number as a currency string<\/p>\n<p><a href=\"#nl_langinfo\">nl_langinfo()<\/a> \u2014 Query language and locale information<\/p>\n<p><a href=\"#nl2br\">nl2br()<\/a> \u2014 Inserts HTML line breaks before all newlines in a string<\/p>\n<p><a href=\"#number_format\">number_format()<\/a> \u2014 Format a number with grouped thousands<\/p>\n<p><a href=\"#ord\">ord()<\/a> \u2014 Convert the first byte of a string to a value between 0 and 255<\/p>\n<p><a href=\"#parse_str\">parse_str()<\/a> \u2014 Parses the string into variables<\/p>\n<p><a href=\"#print\">print()<\/a> \u2014 Output a string<\/p>\n<p><a href=\"#printf\">printf()<\/a> \u2014 Output a formatted string<\/p>\n<p><a href=\"#quoted_printable_decode\">quoted_printable_decode()<\/a> \u2014 Convert a quoted-printable string to an 8 bit string<\/p>\n<p><a href=\"#quoted_printable_encode\">quoted_printable_encode()<\/a> \u2014 Convert a 8 bit string to a quoted-printable string<\/p>\n<p><a href=\"#quotemeta\">quotemeta()<\/a> \u2014 Quote meta characters<\/p>\n<p><a href=\"#rtrim\">rtrim()<\/a> \u2014 Strip whitespace (or other characters) from the end of a string<\/p>\n<p><a href=\"#setlocale\">setlocale()<\/a> \u2014 Set locale information<\/p>\n<p><a href=\"#sha1_file\">sha1_file()<\/a> \u2014 Calculate the sha1 hash of a file<\/p>\n<p><a href=\"#sha1\">sha1()<\/a> \u2014 Calculate the sha1 hash of a string<\/p>\n<p><a href=\"#similar_text\">similar_text()<\/a> \u2014 Calculate the similarity between two strings<\/p>\n<p><a href=\"#soundex\">soundex()<\/a> \u2014 Calculate the soundex key of a string<\/p>\n<p><a href=\"#sprintf\">sprintf()<\/a> \u2014 Return a formatted string<\/p>\n<p><a href=\"#sscanf\">sscanf()<\/a> \u2014 Parses input from a string according to a format<\/p>\n<p><a href=\"#str_getcsv\">str_getcsv()<\/a> \u2014 Parse a CSV string into an array<\/p>\n<p><a href=\"#str_ireplace\">str_ireplace()<\/a> \u2014 Case-insensitive version of str_replace<\/p>\n<p><a href=\"#str_pad\">str_pad()<\/a> \u2014 Pad a string to a certain length with another string<\/p>\n<p><a href=\"#str_repeat\">str_repeat()<\/a> \u2014 Repeat a string<\/p>\n<p><a href=\"#str_replace\">str_replace()<\/a> \u2014 Replace all occurrences of the search string with the replacement string<\/p>\n<p><a href=\"#str_rot13\">str_rot13()<\/a> \u2014 Perform the rot13 transform on a string<\/p>\n<p><a href=\"#str_shuffle\">str_shuffle()<\/a> \u2014 Randomly shuffles a string<\/p>\n<p><a href=\"#str_split\">str_split()<\/a> \u2014 Convert a string to an array<\/p>\n<p><a href=\"#str_word_count\">str_word_count()<\/a> \u2014 Return information about words used in a string<\/p>\n<p><a href=\"#strcasecmp\">strcasecmp()<\/a> \u2014 Binary safe case-insensitive string comparison<\/p>\n<p><a href=\"#strchr\">strchr()<\/a> \u2014 Alias of strstr<\/p>\n<p><a href=\"#strcmp\">strcmp()<\/a> \u2014 Binary safe string comparison<\/p>\n<p><a href=\"#strcoll\">strcoll()<\/a> \u2014 Locale based string comparison<\/p>\n<p><a href=\"#strcspn\">strcspn()<\/a> \u2014 Find length of initial segment not matching mask<\/p>\n<p><a href=\"#strip_tags\">strip_tags()<\/a> \u2014 Strip HTML and PHP tags from a string<\/p>\n<p><a href=\"#stripcslashes\">stripcslashes()<\/a> \u2014 Un-quote string quoted with addcslashes<\/p>\n<p><a href=\"#stripos\">stripos()<\/a> \u2014 Find the position of the first occurrence of a case-insensitive substring in a string<\/p>\n<p><a href=\"#stripslashes\">stripslashes()<\/a> \u2014 Un-quotes a quoted string<\/p>\n<p><a href=\"#stristr\">stristr()<\/a> \u2014 Case-insensitive strstr<\/p>\n<p><a href=\"#strlen\">strlen()<\/a> \u2014 Get string length<\/p>\n<p><a href=\"#strnatcasecmp\">strnatcasecmp()<\/a> \u2014 Case insensitive string comparisons using a &#8220;natural order&#8221; algorithm<\/p>\n<p><a href=\"#strnatcmp\">strnatcmp()<\/a> \u2014 String comparisons using a &#8220;natural order&#8221; algorithm<\/p>\n<p><a href=\"#strncasecmp\">strncasecmp()<\/a> \u2014 Binary safe case-insensitive string comparison of the first n characters<\/p>\n<p><a href=\"#strncmp\">strncmp()<\/a> \u2014 Binary safe string comparison of the first n characters<\/p>\n<p><a href=\"#strpbrk\">strpbrk()<\/a> \u2014 Search a string for any of a set of characters<\/p>\n<p><a href=\"#strpos\">strpos()<\/a> \u2014 Find the position of the first occurrence of a substring in a string<\/p>\n<p><a href=\"#strrchr\">strrchr()<\/a> \u2014 Find the last occurrence of a character in a string<\/p>\n<p><a href=\"#strrev\">strrev()<\/a> \u2014 Reverse a string<\/p>\n<p><a href=\"#strripos\">strripos()<\/a> \u2014 Find the position of the last occurrence of a case-insensitive substring in a string<\/p>\n<p><a href=\"#strrpos\">strrpos()<\/a> \u2014 Find the position of the last occurrence of a substring in a string<\/p>\n<p><a href=\"#strspn\">strspn()<\/a> \u2014 Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask<\/p>\n<p><a href=\"#strstr\">strstr()<\/a> \u2014 Find the first occurrence of a string<\/p>\n<p><a href=\"#strtok\">strtok()<\/a> \u2014 Tokenize string<\/p>\n<p><a href=\"#strtolower\">strtolower()<\/a> \u2014 Make a string lowercase<\/p>\n<p><a href=\"#strtoupper\">strtoupper()<\/a> \u2014 Make a string uppercase<\/p>\n<p><a href=\"#strtr\">strtr()<\/a> \u2014 Translate characters or replace substrings<\/p>\n<p><a href=\"#substr_compare\">substr_compare()<\/a> \u2014 Binary safe comparison of two strings from an offset, up to length characters<\/p>\n<p><a href=\"#substr_count\">substr_count()<\/a> \u2014 Count the number of substring occurrences<\/p>\n<p><a href=\"#substr_replace\">substr_replace()<\/a> \u2014 Replace text within a portion of a string<\/p>\n<p><a href=\"#substr\">substr()<\/a> \u2014 Return part of a string<\/p>\n<p><a href=\"#trim\">trim()<\/a> \u2014 Strip whitespace (or other characters) from the beginning and end of a string<\/p>\n<p><a href=\"#ucfirst\">ucfirst()<\/a> \u2014 Make a string&#8217;s first character uppercase<\/p>\n<p><a href=\"#ucwords\">ucwords()<\/a> \u2014 Uppercase the first character of each word in a string<\/p>\n<p><a href=\"#vfprintf\">vfprintf()<\/a> \u2014 Write a formatted string to a stream<\/p>\n<p><a href=\"#vprintf\">vprintf()<\/a> \u2014 Output a formatted string<\/p>\n<p><a href=\"#vsprintf\">vsprintf()<\/a> \u2014 Return a formatted string<\/p>\n<p><a href=\"#wordwrap\">wordwrap()<\/a> \u2014 Wraps a string to a given number of characters<\/p>\n<h2 id=\"addcslashes\">PHP <code>addcslashes()<\/code> Function<\/h2>\n<h3>What does <code>addcslashes()<\/code> do?<\/h3>\n<p>The PHP <code><code>addcslashes()<\/code><\/code> function will give you a string with backslashes before characters that are listed in <code class=\"parameter\">charlist<\/code> parameter.<\/p>\n<h3>PHP <code>addcslashes()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> addcslashes ( string $str , string $charlist ) : string<\/code><\/pre>\n<h3>PHP <code>addcslashes()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string to be escaped. <\/p>\n<\/li>\n<li>\n<p><code>charlist<\/code> \u2014 A list of characters to be escaped. If charlist contains characters \\n, \\r etc., they are converted in C-like style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 converted to octal representation. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>addcslashes()<\/code> Return Value<\/h3>\n<p>The PHP <code>addcslashes()<\/code> function returns the escaped string.<\/p>\n<h3>PHP <code>addcslashes()<\/code> Working Examples<\/h3>\n<h4>1. addcslashes() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$escaped = addcslashes($not_escaped, \"\\0..\\37!@\\177..\\377\");\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP addcslashes()<\/code> Function<\/h3>\n<p><strong>5.2.5 \u2014 <\/strong> The escape sequences \\v and \\f were added. <\/p>\n<h2 id=\"addslashes\">PHP <code>addslashes()<\/code> Function<\/h2>\n<h3>What does <code>addslashes()<\/code> do?<\/h3>\n<p>The PHP <code><code>addslashes()<\/code><\/code> function will give you a string with backslashes added before characters that need to be escaped. These characters are:<\/p>\n<h3>PHP <code>addslashes()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> addslashes ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>addslashes()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string to be escaped. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>addslashes()<\/code> Return Value<\/h3>\n<p>The PHP <code>addslashes()<\/code> function returns the escaped string.<\/p>\n<h3>PHP <code>addslashes()<\/code> Working Examples<\/h3>\n<h4>1. An addslashes() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Is your name O'Reilly?\";\n\/\/ Outputs: Is your name O\\'Reilly?\necho addslashes($str);\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: wyattstorch42<\/p>\n<pre><code class=\"lang-php\">@ mark at hagers dot demon dot nl :\nYou shouldn't use str_replace() for this. Use a function like htmlentities(), which will properly encode all user input for fields. That way, it will also work if the user types &amp;, &lt;, &gt;, etc.<\/code><\/pre>\n<p>Contributed By: roysimke<\/p>\n<pre><code class=\"lang-php\">Never use addslashes function to escape values you are going to send to mysql. use mysql_real_escape_string or pg_escape at least if you are not using prepared queries yet.\nkeep in mind that single quote is not the only special character that can break your sql query. and quotes are the only thing which addslashes care.<\/code><\/pre>\n<p>Contributed By: svenr<\/p>\n<pre><code class=\"lang-php\">To output a PHP variable to Javascript, use json_encode().\n&lt;?php\n$var = \"He said \\\"Hello O'Reilly\\\" &amp; disappeared.\\nNext line...\";\necho \"alert(\".json_encode($var).\");\\n\";\n?&gt;\nOutput:\nalert(\"He said \\\"Hello O'Reilly\\\" &amp; disappeared.\\nNext line...\") ;<\/code><\/pre>\n<p>Contributed By: mark<\/p>\n<pre><code class=\"lang-php\">I was stumped for a long time by the fact that even when using addslashes and stripslashes explicitly on the field values double quotes (\") still didn't seem to show up in strings read from a database. Until I looked at the source, and realised that the field value is just truncated at the first occurrence of a double quote. the remainder of the string is there (in the source), but is ignored when the form is displayed and submitted.\nThis can easily be solved by replacing double quotes with \"&amp;quot;\" when building the form. like this:\n$fld_value =  str_replace ( \"\\\"\", \"&amp;quot;\", $src_string ) ;\nThe reverse replacement after the form submission is not necessary.<\/code><\/pre>\n<h2 id=\"bin2hex\">PHP <code>bin2hex()<\/code> Function<\/h2>\n<h3>What does <code>bin2hex()<\/code> do?<\/h3>\n<p>The PHP <code><code>bin2hex()<\/code><\/code> function will convert binary data into hexadecimal representation.<\/p>\n<h3>PHP <code>bin2hex()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> bin2hex ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>bin2hex()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 A string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>bin2hex()<\/code> Return Value<\/h3>\n<p>The PHP <code>bin2hex()<\/code> function returns the hexadecimal representation of the given string.<\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: tehjosh<\/p>\n<pre><code class=\"lang-php\">This function is for converting binary data into a hexadecimal string representation.  This function is not for converting strings representing binary digits into hexadecimal.  If you want that functionality, you can simply do this:\n&lt;?php\n$binary = \"11111001\";\n$hex = dechex(bindec($binary));\necho $hex;\n?&gt;\nThis would output \"f9\".  Just remember that there is a very big difference between binary data and a string representation of binary.<\/code><\/pre>\n<h2 id=\"chop\">PHP <code>chop()<\/code> Function<\/h2>\n<h3>What does <code>chop()<\/code> do?<\/h3>\n<p>The PHP <code><code>chop()<\/code><\/code> function will this function is an alias of: <code>rtrim()<\/code>.<\/p>\n<h3>PHP <code>chop()<\/code> Syntax<\/h3>\n<h3>PHP <code>chop()<\/code> Parameters<\/h3>\n<ol><\/ol>\n<p>This function does not accept any parameters.<\/p>\n<h3>Important Points about PHP <code>chop()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> <code>chop()<\/code> is different than the Perl <strong><code>chop()<\/code><\/strong> function, which removes the last character in the string. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Kubo2<\/p>\n<pre><code class=\"lang-php\">Rather use rtrim(). Usage of chop() is not very clear nor consistent for people reading the code after you.<\/code><\/pre>\n<p>Contributed By: JumpIfBelow<\/p>\n<pre><code class=\"lang-php\">If you are searching for a function that does the same trick as chop in PERL, then you should just do the following code:\n&lt;?php\n   $str = substr($str, 0, -1);\n?&gt;\nThe question is: why isn't chop() an alias of the code above, rather than something which will trap developpers?<\/code><\/pre>\n<h2 id=\"chr\">PHP <code>chr()<\/code> Function<\/h2>\n<h3>What does <code>chr()<\/code> do?<\/h3>\n<p>The PHP <code><code>chr()<\/code><\/code> function will generate a single-byte string from a number.<\/p>\n<h3>PHP <code>chr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> chr ( int $bytevalue ) : string<\/code><\/pre>\n<h3>PHP <code>chr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>bytevalue<\/code> \u2014 An integer between 0 and 255. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>chr()<\/code> Return Value<\/h3>\n<p>The PHP <code>chr()<\/code> function returns a single-character string containing the specified byte.<\/p>\n<h3>PHP <code>chr()<\/code> Working Examples<\/h3>\n<h4>1. chr() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Assumes the string will be used as ASCII or an ASCII-compatible encoding\n$str = \"The string ends in escape: \";\n$str .= chr(27); \/* add an escape character at the end of $str *\/\n\/* Often this is more useful *\/\n$str = sprintf(\"The string ends in escape: %c\", 27);\n?&gt;<\/code><\/pre>\n<h4>2. Overflow behavior<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho chr(-159), chr(833), PHP_EOL;\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">aA<\/code><\/pre>\n<h4>3. Building a UTF-8 string from individual bytes<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\ndeclare(encoding='UTF-8');\n$str = chr(240) . chr(159) . chr(144) . chr(152);\necho $str;\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\"><br>\n\ud83d\udc18<br><\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: perrodin<\/p>\n<pre><code class=\"lang-php\">Note that if the number is higher than 256, it will return the number mod 256.\nFor example :\nchr(321)=A because A=65(256)<\/code><\/pre>\n<h2 id=\"chunk_split\">PHP <code>chunk_split()<\/code> Function<\/h2>\n<h3>What does <code>chunk_split()<\/code> do?<\/h3>\n<p>The PHP <code><code>chunk_split()<\/code><\/code> function will can be used to split a string into smaller chunks which is useful for e.g. converting <code>base64_encode()<\/code> output to match RFC 2045 semantics. It inserts <code class=\"parameter\">end<\/code> every <code class=\"parameter\">chunklen<\/code> characters.<\/p>\n<h3>PHP <code>chunk_split()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> chunk_split ( string $body [, int $chunklen = 76 [, string $end = \"\\r\\n\" ]] ) : string<\/code><\/pre>\n<h3>PHP <code>chunk_split()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>body<\/code> \u2014 The string to be chunked. <\/p>\n<\/li>\n<li>\n<p><code>chunklen<\/code> \u2014 The chunk length. <\/p>\n<\/li>\n<li>\n<p><code>end<\/code> \u2014 The line ending sequence. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>chunk_split()<\/code> Return Value<\/h3>\n<p>The PHP <code>chunk_split()<\/code> function returns the chunked string.<\/p>\n<h3>PHP <code>chunk_split()<\/code> Working Examples<\/h3>\n<h4>1. chunk_split() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ format $data using RFC 2045 semantics\n$new_string = chunk_split(base64_encode($data));\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">An alternative for unicode strings;\n&lt;?php\nfunction chunk_split_unicode($str, $l = 76, $e = \"\\r\\n\") {\n    $tmp = array_chunk(\n        preg_split(\"\/\/u\", $str, -1, PREG_SPLIT_NO_EMPTY), $l);\n    $str = \"\";\n    foreach ($tmp as $t) {\n        $str .= join(\"\", $t) . $e;\n    }\n    return $str;\n}\n$str = \"Yar\u0131m kilo \u00e7ay, yar\u0131m kilo \u015feker\";\necho chunk_split($str, 4) .\"\\n\";\necho chunk_split_unicode($str, 4);\n?&gt;\nYar\ufffd\n\ufffdm k\nilo \n\u00e7ay\n, ya\nr\u0131m\n kil\no \u015f\neker\nYar\u0131\nm ki\nlo \u00e7\nay, \nyar\u0131\nm ki\nlo \u015f\neker<\/code><\/pre>\n<h2 id=\"convert_cyr_string\">PHP <code>convert_cyr_string()<\/code> Function<\/h2>\n<h3>What does <code>convert_cyr_string()<\/code> do?<\/h3>\n<p>The PHP <code><code>convert_cyr_string()<\/code><\/code> function will convert from one Cyrillic character set to another.<\/p>\n<h3>PHP <code>convert_cyr_string()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> convert_cyr_string ( string $str , string $from , string $to ) : string<\/code><\/pre>\n<h3>PHP <code>convert_cyr_string()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string to be converted. <\/p>\n<\/li>\n<li>\n<p><code>from<\/code> \u2014 The source Cyrillic character set, as a single character. <\/p>\n<\/li>\n<li>\n<p><code>to<\/code> \u2014 The target Cyrillic character set, as a single character. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>convert_cyr_string()<\/code> Return Value<\/h3>\n<p>The PHP <code>convert_cyr_string()<\/code> function returns the converted string.<\/p>\n<h2 id=\"convert_uudecode\">PHP <code>convert_uudecode()<\/code> Function<\/h2>\n<h3>What does <code>convert_uudecode()<\/code> do?<\/h3>\n<p>The PHP <code><code>convert_uudecode()<\/code><\/code> function will <code>convert_uudecode()<\/code> decodes a uuencoded string.<\/p>\n<h3>PHP <code>convert_uudecode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> convert_uudecode ( string $data ) : string<\/code><\/pre>\n<h3>PHP <code>convert_uudecode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>data<\/code> \u2014 The uuencoded data. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>convert_uudecode()<\/code> Return Value<\/h3>\n<p>The PHP <code>convert_uudecode()<\/code> function returns the decoded data as a string or <code>FALSE<\/code> on failure.<\/p>\n<h3>PHP <code>convert_uudecode()<\/code> Working Examples<\/h3>\n<h4>1. convert_uudecode() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho convert_uudecode(\"+22!L;W9E(%!(4\\\"$`\\n`\");\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">I love PHP!<\/code><\/pre>\n<h2 id=\"convert_uuencode\">PHP <code>convert_uuencode()<\/code> Function<\/h2>\n<h3>What does <code>convert_uuencode()<\/code> do?<\/h3>\n<p>The PHP <code><code>convert_uuencode()<\/code><\/code> function will <code>convert_uuencode()<\/code> encodes a string using the uuencode algorithm.<\/p>\n<h3>PHP <code>convert_uuencode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> convert_uuencode ( string $data ) : string<\/code><\/pre>\n<h3>PHP <code>convert_uuencode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>data<\/code> \u2014 The data to be encoded. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>convert_uuencode()<\/code> Return Value<\/h3>\n<p>The PHP <code>convert_uuencode()<\/code> function returns the uuencoded data or <code>FALSE<\/code> on failure.<\/p>\n<h3>PHP <code>convert_uuencode()<\/code> Working Examples<\/h3>\n<h4>1. convert_uuencode() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$some_string = \"test\\ntext text\\r\\n\";\necho convert_uuencode($some_string);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">0=&amp;5S=`IT97AT('1E&gt;'0-\"@``\n`<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: root<\/p>\n<pre><code class=\"lang-php\">@Craig's note: base64_encode() is better suited for that. In fact, it produces smaller output and operates slightly faster. I did a little benchmark -- here are my findings:\nFile: JPG, 631614 bytes\n== Base64 ==\nexecution time: 0.0039639472961426 secs\noutput length: 842152\n== UUencode ==\nexecution time: 0.004105806350708 secs\noutput length: 870226<\/code><\/pre>\n<h2 id=\"count_chars\">PHP <code>count_chars()<\/code> Function<\/h2>\n<h3>What does <code>count_chars()<\/code> do?<\/h3>\n<p>The PHP <code><code>count_chars()<\/code><\/code> function will give you <\/p>\n<h3>PHP <code>count_chars()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> count_chars ( string $string [, int $mode = 0 ] ) : mixed<\/code><\/pre>\n<h3>PHP <code>count_chars()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The examined string. <\/p>\n<\/li>\n<li>\n<p><code>mode<\/code> \u2014 See return values. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>count_chars()<\/code> Return Value<\/h3>\n<p>The PHP <code>count_chars()<\/code> function returns one of the following:<\/p>\n<h3>PHP <code>count_chars()<\/code> Working Examples<\/h3>\n<h4>1. count_chars() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$data = \"Two Ts and one F.\";\nforeach (count_chars($data, 1) as $i =&gt; $val) {\n   echo \"There were $val instance(s) of \\\"\" , chr($i) , \"\\\" in the string.\\n\";\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">There were 4 instance(s) of \" \" in the string.\nThere were 1 instance(s) of \".\" in the string.\nThere were 1 instance(s) of \"F\" in the string.\nThere were 2 instance(s) of \"T\" in the string.\nThere were 1 instance(s) of \"a\" in the string.\nThere were 1 instance(s) of \"d\" in the string.\nThere were 1 instance(s) of \"e\" in the string.\nThere were 2 instance(s) of \"n\" in the string.\nThere were 2 instance(s) of \"o\" in the string.\nThere were 1 instance(s) of \"s\" in the string.\nThere were 1 instance(s) of \"w\" in the string.<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: marcus33cz<\/p>\n<pre><code class=\"lang-php\">If you have problems using count_chars with a multibyte string, you can change the page encoding. Alternatively, you can also use this mb_count_chars version of the function. Basically it is mode \"1\" of the original function.\n&lt;?php\n\/**\n * Counts character occurences in a multibyte string\n * @param string $input UTF-8 data\n * @return array associative array of characters.\n *\/\nfunction mb_count_chars($input) {\n    $l = mb_strlen($input, 'UTF-8');\n    $unique = array();\n    for($i = 0; $i &lt; $l; $i++) {\n        $char = mb_substr($input, $i, 1, 'UTF-8');\n        if(!array_key_exists($char, $unique))\n            $unique[$char] = 0;\n        $unique[$char]++;\n    }\n    return $unique;\n}\n$input = \"Let's try some Greek letters: \u03b1\u03b1\u03b1\u03b1\u03b1\u0395\u03b5\u0399\u03b9\u039c\u03bc\u03a8\u03c8, Russian: \u0419\u0419\u042b\u042b\u0429\u041d, Czech: \u011b\u0161\u010d\u0159\u017e\u00fd\u00e1\u00ed\u00e9\";\nprint_r( mb_count_chars($input) ); \n\/\/returns: Array ( [L] =&gt; 1 [e] =&gt; 7 [t] =&gt; 4 ['] =&gt; 1 [s] =&gt; 5 [ ] =&gt; 9 [r] =&gt; 3 [y] =&gt; 1 [o] =&gt; 1 [m] =&gt; 1 [G] =&gt; 1 [k] =&gt; 1 [l] =&gt; 1 [:] =&gt; 3 [\u03b1] =&gt; 5 [\u0395] =&gt; 1 [\u03b5] =&gt; 1 [\u0399] =&gt; 1 [\u03b9] =&gt; 1 [\u039c] =&gt; 1 [\u03bc] =&gt; 1 [\u03a8] =&gt; 1 [\u03c8] =&gt; 1 [,] =&gt; 2 [R] =&gt; 1 [u] =&gt; 1 [i] =&gt; 1 [a] =&gt; 1 [n] =&gt; 1 [\u0419] =&gt; 2 [\u042b] =&gt; 2 [\u0429] =&gt; 1 [\u041d] =&gt; 1 [C] =&gt; 1 [z] =&gt; 1 [c] =&gt; 1 [h] =&gt; 1 [\u011b] =&gt; 1 [\u0161] =&gt; 1 [\u010d] =&gt; 1 [\u0159] =&gt; 1 [\u017e] =&gt; 1 [\u00fd] =&gt; 1 [\u00e1] =&gt; 1 [\u00ed] =&gt; 1 [\u00e9] =&gt; 1 )\n?&gt;<\/code><\/pre>\n<h2 id=\"crc32\">PHP <code>crc32()<\/code> Function<\/h2>\n<h3>What does <code>crc32()<\/code> do?<\/h3>\n<p>The PHP <code><code>crc32()<\/code><\/code> function will calculates the crc32 polynomial of a string.<\/p>\n<h3>PHP <code>crc32()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> crc32 ( string $str ) : int<\/code><\/pre>\n<h3>PHP <code>crc32()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The data. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>crc32()<\/code> Return Value<\/h3>\n<p>The PHP <code>crc32()<\/code> function returns the crc32 checksum of <code class=\"parameter\">str<\/code> as an integer.<\/p>\n<h3>PHP <code>crc32()<\/code> Working Examples<\/h3>\n<h4>1. Displaying a crc32 checksum<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$checksum = crc32(\"The quick brown fox jumped over the lazy dog.\");\nprintf(\"%u\\n\", $checksum);\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>crc32()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Because PHP&#8217;s integer type is signed many crc32 checksums will result in negative integers on 32bit platforms. On 64bit installations all <code>crc32()<\/code> results will be positive integers though. <\/p>\n<\/li>\n<li>\n<p> So you need to use the &#8220;%u&#8221; formatter of <code>sprintf()<\/code> or <code>printf()<\/code> to get the string representation of the unsigned <code>crc32()<\/code> checksum in decimal format. <\/p>\n<\/li>\n<li>\n<p> For a hexadecimal representation of the checksum you can either use the &#8220;%x&#8221; formatter of <code>sprintf()<\/code> or <code>printf()<\/code> or the <code>dechex()<\/code> conversion functions, both of these also take care of converting the <code>crc32()<\/code> result to an unsigned integer. <\/p>\n<\/li>\n<li>\n<p> Having 64bit installations also return negative integers for higher result values was considered but would break the hexadecimal conversion as negatives would get an extra 0xFFFFFFFF######## offset then. As hexadecimal representation seems to be the most common use case we decided to not break this even if it breaks direct decimal comparisons in about 50% of the cases when moving from 32 to 64bits. <\/p>\n<\/li>\n<li>\n<p> In retrospect having the function return an integer maybe wasn&#8217;t the best idea and returning a hex string representation right away (as e.g. <code>md5()<\/code> does) might have been a better plan to begin with. <\/p>\n<\/li>\n<li>\n<p> For a more portable solution you may also consider the generic <code>hash()<\/code>. <code class=\"code\">hash(\"crc32b\", $str)<\/code> will return the same string as <code class=\"code\">str_pad(dechex(crc32($str)), 8, '0', STR_PAD_LEFT)<\/code>. <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"crypt\">PHP <code>crypt()<\/code> Function<\/h2>\n<h3>What does <code>crypt()<\/code> do?<\/h3>\n<p>The PHP <code><code>crypt()<\/code><\/code> function will give you a hashed string using the standard Unix DES-based algorithm or alternative algorithms that may be available on the system.<\/p>\n<h3>PHP <code>crypt()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> crypt ( string $str [, string $salt ] ) : string<\/code><\/pre>\n<h3>PHP <code>crypt()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string to be hashed. <\/p>\n<\/li>\n<li>\n<p><code>salt<\/code> \u2014 An optional salt string to base the hashing on. If not provided, the behaviour is defined by the algorithm implementation and can lead to unexpected results. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>crypt()<\/code> Return Value<\/h3>\n<p>The PHP <code>crypt()<\/code> function returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure.<\/p>\n<h3>PHP <code>crypt()<\/code> Working Examples<\/h3>\n<h4>1. crypt() examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$hashed_password = crypt('mypassword'); \/\/ let the salt be automatically generated\n\/* You should pass the entire results of crypt() as the salt for comparing a\n   password, to avoid problems when different hashing algorithms are used. (As\n   it says above, standard DES-based password hashing uses a 2-character salt,\n   but MD5-based hashing uses 12.) *\/\nif (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {\n   echo \"Password verified!\";\n}\n?&gt;<\/code><\/pre>\n<h4>2. Using crypt() with htpasswd<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Set the password\n$password = 'mypassword';\n\/\/ Get the hash, letting the salt be automatically generated\n$hash = crypt($password);\n?&gt;<\/code><\/pre>\n<h4>3. Using crypt() with different hash types<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/* These salts are examples only, and should not be used verbatim in your code.\n   You should generate a distinct, correctly-formatted salt for each password.\n*\/\nif (CRYPT_STD_DES == 1) {\n    echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . \"\\n\";\n}\nif (CRYPT_EXT_DES == 1) {\n    echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . \"\\n\";\n}\nif (CRYPT_MD5 == 1) {\n    echo 'MD5:          ' . crypt('rasmuslerdorf', '$1$rasmusle$') . \"\\n\";\n}\nif (CRYPT_BLOWFISH == 1) {\n    echo 'Blowfish:     ' . crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') . \"\\n\";\n}\nif (CRYPT_SHA256 == 1) {\n    echo 'SHA-256:      ' . crypt('rasmuslerdorf', '$5$rounds=5000$usesomesillystringforsalt$') . \"\\n\";\n}\nif (CRYPT_SHA512 == 1) {\n    echo 'SHA-512:      ' . crypt('rasmuslerdorf', '$6$rounds=5000$usesomesillystringforsalt$') . \"\\n\";\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Standard DES: rl.3StKT.4T8M\nExtended DES: _J9..rasmBYk8r9AiWNc\nMD5: $1$rasmusle$rISCgZzpwk3UhDidwXvin0\nBlowfish: $2a$07$usesomesillystringfore2uDLvp1Ii2e.\/U9C8sBjqp8I90dH6hi\nSHA-256: $5$rounds=5000$usesomesillystri$KqJWpanXZHKq2BOB43TSaYhEWsQ1Lr5QNyPCDH\/Tp.6\nSHA-512: $6$rounds=5000$usesomesillystri$D4IrlXatmP7rx3P3InaxBeoomnAihCKRVQP22JZ6EY47Wc6BkroIuUUBOov1i.S5KPgErtP\/EN5mcO.ChWQW21<\/code><\/pre>\n<h3>Changelog for PHP crypt()<\/code> Function<\/h3>\n<p><strong>5.6.5 \u2014 <\/strong> When the failure string &#8220;*0&#8221; is given as the <code class=\"parameter\">salt<\/code>, &#8220;*1&#8221; will now be returned for consistency with other crypt implementations. Prior to this version, PHP 5.6 would incorrectly return a DES hash. <\/p>\n<p><strong>5.6.0 \u2014 <\/strong> Raise E_NOTICE security warning if <code class=\"parameter\">salt<\/code> is omitted. <\/p>\n<p><strong>5.5.21 \u2014 <\/strong> When the failure string &#8220;*0&#8221; is given as the <code class=\"parameter\">salt<\/code>, &#8220;*1&#8221; will now be returned for consistency with other crypt implementations. Prior to this version, PHP 5.5 (and earlier branches) would incorrectly return a DES hash. <\/p>\n<p><strong>5.3.7 \u2014 <\/strong> Added $2x$ and $2y$ Blowfish modes to deal with potential high-bit attacks. <\/p>\n<p><strong>5.3.2 \u2014 <\/strong> Added SHA-256 and SHA-512 crypt based on Ulrich Drepper&#8217;s \u00bb implementation. <\/p>\n<p><strong>5.3.2 \u2014 <\/strong> Fixed Blowfish behaviour on invalid rounds to return &#8220;failure&#8221; string (&#8220;*0&#8221; or &#8220;*1&#8221;), instead of falling back to DES. <\/p>\n<p><strong>5.3.0 \u2014 <\/strong> PHP now contains its own implementation for the MD5 crypt, Standard DES, Extended DES and the Blowfish algorithms and will use that if the system lacks of support for one or more of the algorithms. <\/p>\n<h3>Important Points about PHP <code>crypt()<\/code> Function<\/h3>\n<ol>\n<li>\n<p>This function is not (yet) binary safe!<\/p>\n<\/li>\n<li>\n<p> As of PHP 5.3.0, PHP contains its own implementation and will use that if the system lacks of support for one or more of the algorithms. <\/p>\n<\/li>\n<li>\n<p> Using the <code>CRYPT_BLOWFISH<\/code> algorithm, will result in the <code class=\"parameter\">str<\/code> parameter being truncated to a maximum length of 72 characters. <\/p>\n<\/li>\n<li>\n<p> When validating passwords, a string comparison function that isn&#8217;t vulnerable to timing attacks should be used to compare the output of <code>crypt()<\/code> to the previously known hash. PHP 5.6 onwards provides <code>hash_equals()<\/code> for this purpose. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: bob dot orr<\/p>\n<pre><code class=\"lang-php\">The #2 comment on this comments page (as of Feb 2015) is 9 years old and recommends phpass.  I have independently security audited this product and, while it continues to be recommended for password security, it is actually insecure and should NOT be used.  It hasn't seen any updates in years (still at v0.3) and there are more recent alternatives such as using the newer built-in PHP password_hash() function that are much better.  Everyone, please take a few moments to confirm what I'm saying is accurate (i.e. review the phpass code for yourself) and then click the down arrow to sink the phpass comment to the bottom.  You'll be increasing security across the Internet by doing so.\nFor those who want details:  md5() with microtime() are a fallback position within the source code of phpass.  Instead of terminating, it continues to execute code.  The author's intentions of trying to work everywhere are admirable but, when it comes to application security, that stance actually backfires.  The only correct answer in a security context is to terminate the application rather than fallback to a weak position that can potentially be exploited (usually by forcing that weaker position to happen).<\/code><\/pre>\n<p>Contributed By: Marten Jacobs<\/p>\n<pre><code class=\"lang-php\">As I understand it, blowfish is generally seen a secure hashing algorithm, even for enterprise use (correct me if I'm wrong). Because of this, I created functions to create and check secure password hashes using this algorithm, and using the (also deemed cryptographically secure) openssl_random_pseudo_bytes function to generate the salt.\n&lt;?php\n\/*\n * Generate a secure hash for a given password. The cost is passed\n * to the blowfish algorithm. Check the PHP manual page for crypt to\n * find more information about this setting.\n *\/\nfunction generate_hash($password, $cost=11){\n        \/* To generate the salt, first generate enough random bytes. Because\n         * base64 returns one character for each 6 bits, the we should generate\n         * at least 22*6\/8=16.5 bytes, so we generate 17. Then we get the first\n         * 22 base64 characters\n         *\/\n        $salt=substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22);\n        \/* As blowfish takes a salt with the alphabet .\/A-Za-z0-9 we have to\n         * replace any '+' in the base64 string with '.'. We don't have to do\n         * anything about the '=', as this only occurs when the b64 string is\n         * padded, which is always after the first 22 characters.\n         *\/\n        $salt=str_replace(\"+\",\".\",$salt);\n        \/* Next, create a string that will be passed to crypt, containing all\n         * of the settings, separated by dollar signs\n         *\/\n        $param='$'.implode('$',array(\n                \"2y\", \/\/select the most secure version of blowfish (&gt;=PHP 5.3.7)\n                str_pad($cost,2,\"0\",STR_PAD_LEFT), \/\/add the cost in two digits\n                $salt \/\/add the salt\n        ));\n       \n        \/\/now do the actual hashing\n        return crypt($password,$param);\n}\n \n\/*\n * Check the password against a hash generated by the generate_hash\n * function.\n *\/\nfunction validate_pw($password, $hash){\n        \/* Regenerating the with an available hash as the options parameter should\n         * produce the same hash if the same password is passed.\n         *\/\n        return crypt($password, $hash)==$hash;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"echo\">PHP <code>echo()<\/code> Function<\/h2>\n<h3>What does <code>echo()<\/code> do?<\/h3>\n<p>The PHP <code><code>echo()<\/code><\/code> function will outputs all parameters. No additional newline is appended.<\/p>\n<h3>PHP <code>echo()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> echo ( string $arg1 [, string $... ] ) : void<\/code><\/pre>\n<h3>PHP <code>echo()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg1<\/code> \u2014 The parameter to output. <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>echo()<\/code> Return Value<\/h3>\n<p>The PHP <code>echo()<\/code> function returns d.<\/p>\n<h3>PHP <code>echo()<\/code> Working Examples<\/h3>\n<h4>1. echo examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho \"Hello World\";\n\/\/ Strings can either be passed individually as multiple arguments or\n\/\/ concatenated together and passed as a single argument\necho 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);\necho 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . \"\\n\";\n\/\/ Because echo does not behave like a function, the following code is invalid.\n($some_var) ? echo 'true' : echo 'false';\n\/\/ However, the following examples will work:\n($some_var) ? print 'true' : print 'false'; \/\/ print is also a construct, but\n                                            \/\/ it behaves like a function, so\n                                            \/\/ it may be used in this context.\necho $some_var ? 'true': 'false'; \/\/ changing the statement around\n?&gt;<\/code><\/pre>\n<h2 id=\"explode\">PHP <code>explode()<\/code> Function<\/h2>\n<h3>What does <code>explode()<\/code> do?<\/h3>\n<p>The PHP <code><code>explode()<\/code><\/code> function will give you an array of strings, each of which is a substring of <code class=\"parameter\">string<\/code> formed by splitting it on boundaries formed by the string <code class=\"parameter\">delimiter<\/code>.<\/p>\n<h3>PHP <code>explode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] ) : array<\/code><\/pre>\n<h3>PHP <code>explode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>delimiter<\/code> \u2014 The boundary string. <\/p>\n<\/li>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>limit<\/code> \u2014 If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>explode()<\/code> Return Value<\/h3>\n<p>The PHP <code>explode()<\/code> function returns an array of strings created by splitting the <code class=\"parameter\">string<\/code> parameter on boundaries formed by the <code class=\"parameter\">delimiter<\/code>.<\/p>\n<h3>PHP <code>explode()<\/code> Working Examples<\/h3>\n<h4>1. explode() examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Example 1\n$pizza  = \"piece1 piece2 piece3 piece4 piece5 piece6\";\n$pieces = explode(\" \", $pizza);\necho $pieces[0]; \/\/ piece1\necho $pieces[1]; \/\/ piece2\n\/\/ Example 2\n$data = \"foo:*:1023:1000::\/home\/foo:\/bin\/sh\";\nlist($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(\":\", $data);\necho $user; \/\/ foo\necho $pass; \/\/ *\n?&gt;<\/code><\/pre>\n<h4>2. explode() return examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/* \n   A string that doesn't contain the delimiter will simply\n   return a one-length array of the original string.\n*\/\n$input1 = \"hello\";\n$input2 = \"hello,there\";\n$input3 = ',';\nvar_dump( explode( ',', $input1 ) );\nvar_dump( explode( ',', $input2 ) );\nvar_dump( explode( ',', $input3 ) );\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">array(1)\n(\n [0] =&gt; string(5) \"hello\"\n)\narray(2)\n(\n [0] =&gt; string(5) \"hello\"\n [1] =&gt; string(5) \"there\"\n)\narray(2)\n(\n [0] =&gt; string(0) \"\"\n [1] =&gt; string(0) \"\"\n)<\/code><\/pre>\n<h4>3. limit parameter examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = 'one|two|three|four';\n\/\/ positive limit\nprint_r(explode('|', $str, 2));\n\/\/ negative limit (since PHP 5.1)\nprint_r(explode('|', $str, -1));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Array\n(\n [0] =&gt; one\n [1] =&gt; two|three|four\n)\nArray\n(\n [0] =&gt; one\n [1] =&gt; two\n [2] =&gt; three\n)<\/code><\/pre>\n<h3>Changelog for PHP explode()<\/code> Function<\/h3>\n<p><strong>5.1.0 \u2014 <\/strong> Support for negative <code class=\"parameter\">limit<\/code>s was added <\/p>\n<h3>Important Points about PHP <code>explode()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Although <code>implode()<\/code> can, for historical reasons, accept its parameters in either order, <code>explode()<\/code> cannot. You must ensure that the <code class=\"parameter\">delimiter<\/code> argument comes before the <code class=\"parameter\">string<\/code> argument. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: php<\/p>\n<pre><code class=\"lang-php\">Here is my approach to have exploded output with multiple delimiter. \n&lt;?php\n\/\/$delimiters has to be array\n\/\/$string has to be array\nfunction multiexplode ($delimiters,$string) {\n    \n    $ready = str_replace($delimiters, $delimiters[0], $string);\n    $launch = explode($delimiters[0], $ready);\n    return  $launch;\n}\n$text = \"here is a sample: this text, and this will be exploded. this also | this one too :)\";\n$exploded = multiexplode(array(\",\",\".\",\"|\",\":\"),$text);\nprint_r($exploded);\n\/\/And output will be like this:\n\/\/ Array\n\/\/ (\n\/\/    [0] =&gt; here is a sample\n\/\/    [1] =&gt;  this text\n\/\/    [2] =&gt;  and this will be exploded\n\/\/    [3] =&gt;  this also \n\/\/    [4] =&gt;  this one too \n\/\/    [5] =&gt; )\n\/\/ )\n?&gt;<\/code><\/pre>\n<p>Contributed By: tiago dot dias<\/p>\n<pre><code class=\"lang-php\">Beaware splitting empty strings.\n&lt;?php\n$str = \"\";\n$res = explode(\",\", $str);\nprint_r($res);\n?&gt;\nIf you split an empty string, you get back a one-element array with 0 as the key and an empty string for the value.\nArray\n(\n    [0] =&gt; \n)\nTo solve this, just use array_filter() without callback. Quoting manual page \"If the callback function is not supplied, array_filter() will remove all the entries of input that are equal to FALSE.\".\n&lt;?php\n$str = \"\";\n$res = array_filter(explode(\",\", $str));\nprint_r($res);\n?&gt;\nArray\n(\n)<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">The comments to use array_filter() without a callback to remove empty strings from explode's results miss the fact that array_filter will remove all elements that, to quote the manual,  \"are equal to FALSE\".\nThis includes, in particular, the string \"0\", which is NOT an empty string.\nIf you really want to filter out empty strings, use the defining feature of the empty string that it is the only string that has a length of 0. So:\n&lt;?php\narray_filter(explode(':', \"1:2::3:0:4\"), 'strlen');\n?&gt;<\/code><\/pre>\n<p>Contributed By: eye_syah88<\/p>\n<pre><code class=\"lang-php\">A simple one line method to explode &amp; trim whitespaces from the exploded elements\narray_map('trim',explode(\",\",$str));\nexample:\n$str=\"one  ,two  ,       three  ,  four    \"; \nprint_r(array_map('trim',explode(\",\",$str)));\nOutput:\nArray ( [0] =&gt; one [1] =&gt; two [2] =&gt; three [3] =&gt; four )<\/code><\/pre>\n<p>Contributed By: m0gr14<\/p>\n<pre><code class=\"lang-php\">Here's a function for \"multi\" exploding a string.\n&lt;?php\n\/\/the function\n\/\/Param 1 has to be an Array\n\/\/Param 2 has to be a String\nfunction multiexplode ($delimiters,$string) {\n    $ary = explode($delimiters[0],$string);\n    array_shift($delimiters);\n    if($delimiters != NULL) {\n        foreach($ary as $key =&gt; $val) {\n             $ary[$key] = multiexplode($delimiters, $val);\n        }\n    }\n    return  $ary;\n}\n\/\/ Example of use\n$string = \"1-2-3|4-5|6:7-8-9-0|1,2:3-4|5\";\n$delimiters = Array(\",\",\":\",\"|\",\"-\");\n$res = multiexplode($delimiters,$string);\necho '&lt;pre&gt;';\nprint_r($res);\necho '&lt;\/pre&gt;';\n\/\/returns\n\/*\nArray\n(\n    [0] =&gt; Array\n        (\n            [0] =&gt; Array\n                (\n                    [0] =&gt; Array\n                        (\n                            [0] =&gt; 1\n                            [1] =&gt; 2\n                            [2] =&gt; 3\n                        )\n                    [1] =&gt; Array\n                        (\n                            [0] =&gt; 4\n                            [1] =&gt; 5\n                        )\n                    [2] =&gt; Array\n                        (\n                            [0] =&gt; 6\n                        )\n                )\n            [1] =&gt; Array\n                (\n                    [0] =&gt; Array\n                        (\n                            [0] =&gt; 7\n                            [1] =&gt; 8\n                            [2] =&gt; 9\n                            [3] =&gt; 0\n                        )\n                    [1] =&gt; Array\n                        (\n                            [0] =&gt; 1\n                        )\n                )\n        )\n    [1] =&gt; Array\n        (\n            [0] =&gt; Array\n                (\n                    [0] =&gt; Array\n                        (\n                            [0] =&gt; 2\n                        )\n                )\n            [1] =&gt; Array\n                (\n                    [0] =&gt; Array\n                        (\n                            [0] =&gt; 3\n                            [1] =&gt; 4\n                        )\n                    [1] =&gt; Array\n                        (\n                            [0] =&gt; 5\n                        )\n                )\n        )\n)\n*\/\n?&gt;<\/code><\/pre>\n<p>Contributed By: Anonymous<\/p>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ converts pure string into a trimmed keyed array\nfunction string2KeyedArray($string, $delimiter = ',', $kv = '=&gt;') {\n  if ($a = explode($delimiter, $string)) { \/\/ create parts\n    foreach ($a as $s) { \/\/ each part\n      if ($s) {\n        if ($pos = strpos($s, $kv)) { \/\/ key\/value delimiter\n          $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));\n        } else { \/\/ key delimiter not found\n          $ka[] = trim($s);\n        }\n      }\n    }\n    return $ka;\n  }\n} \/\/ string2KeyedArray\n$string = 'a=&gt;1, b=&gt;23   , $a, c=&gt; 45% , true,d =&gt; ab c ';\nprint_r(string2KeyedArray($string));\n?&gt;\nArray\n(\n  [a] =&gt; 1\n  [b] =&gt; 23\n  [0] =&gt; $a\n  [c] =&gt; 45%\n  [1] =&gt; true\n  [d] =&gt; ab c\n)<\/code><\/pre>\n<p>Contributed By: kkobashi<\/p>\n<pre><code class=\"lang-php\">Explode does not parse a string by delimiters, in the sense that we expect to find tokens between a starting and ending delimiter, but instead splits a string into parts by using a string as the boundary of each part. Once that boundary is discovered the string is split. Whether or not that boundary is proceeded or superseded by any data is irrelevant since the parts are determined at the point a boundary is discovered. \n \nFor example: \n \n&lt;?php \n \nvar_dump(explode(\"\/\",\"\/\")); \n \n\/* \n   Outputs \n \n   array(2) { \n     [0]=&gt; \n     string(0) \"\" \n     [1]=&gt; \n     string(0) \"\" \n   } \n*\/ \n \n?&gt; \n \nThe reason we have two empty strings here is that a boundary is discovered before any data has been collected from the string. The boundary splits the string into two parts even though those parts are empty. \n \nOne way to avoid getting back empty parts (if you don't care for those empty parts) is to use array_filter on the result. \n \n&lt;?php \n \nvar_dump(array_filter(explode(\"\/\",\"\/\"))); \n \n\/* \n   Outputs \n \n   array(0) { \n   } \n*\/ \n?&gt; \n \n*[This note was edited by googleguy at php dot net for clarity]*<\/code><\/pre>\n<h2 id=\"fprintf\">PHP <code>fprintf()<\/code> Function<\/h2>\n<h3>What does <code>fprintf()<\/code> do?<\/h3>\n<p>The PHP <code><code>fprintf()<\/code><\/code> function will write a string produced according to <code class=\"parameter\">format<\/code> to the stream resource specified by <code class=\"parameter\">handle<\/code>.<\/p>\n<h3>PHP <code>fprintf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> fprintf ( resource $handle , string $format [, mixed $... ] ) : int<\/code><\/pre>\n<h3>PHP <code>fprintf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>handle<\/code> \u2014 A file system pointer resource that is typically created using <code>fopen()<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>fprintf()<\/code> Return Value<\/h3>\n<p>The PHP <code>fprintf()<\/code> function returns the length of the string written.<\/p>\n<h3>PHP <code>fprintf()<\/code> Working Examples<\/h3>\n<h4>1. fprintf(): zero-padded integers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nif (!($fp = fopen('date.txt', 'w'))) {\n    return;\n}\nfprintf($fp, \"%04d-%02d-%02d\", $year, $month, $day);\n\/\/ will write the formatted ISO date to date.txt\n?&gt;<\/code><\/pre>\n<h4>2. fprintf(): formatting currency<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nif (!($fp = fopen('currency.txt', 'w'))) {\n    return;\n}\n$money1 = 68.75;\n$money2 = 54.35;\n$money = $money1 + $money2;\n\/\/ echo $money will output \"123.1\";\n$len = fprintf($fp, '%01.2f', $money);\n\/\/ will write \"123.10\" to currency.txt\necho \"wrote $len bytes to currency.txt\";\n\/\/ use the return value of fprintf to determine how many bytes we wrote\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>fprintf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"get_html_translation_table\">PHP <code>get_html_translation_table()<\/code> Function<\/h2>\n<h3>What does <code>get_html_translation_table()<\/code> do?<\/h3>\n<p>The PHP <code><code>get_html_translation_table()<\/code><\/code> function will give you the translation table used by <code>htmlspecialchars()<\/code> and <code>htmlentities()<\/code>.<\/p>\n<h3>PHP <code>get_html_translation_table()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> get_html_translation_table ([ int $table = HTML_SPECIALCHARS [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = \"UTF-8\" ]]] ) : array<\/code><\/pre>\n<h3>PHP <code>get_html_translation_table()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>table<\/code> \u2014 Which table to return. Either HTML_ENTITIES or HTML_SPECIALCHARS. <\/p>\n<\/li>\n<li>\n<p><code>flags<\/code> \u2014 A bitmask of one or more of the following flags, which specify which quotes the table will contain as well as which document type the table is for. The default is ENT_COMPAT | ENT_HTML401. <\/p>\n<\/li>\n<li>\n<p><code>encoding<\/code> \u2014 Encoding to use. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>get_html_translation_table()<\/code> Return Value<\/h3>\n<p>The PHP <code>get_html_translation_table()<\/code> function returns the translation table as an array, with the original characters as keys and entities as values.<\/p>\n<h3>PHP <code>get_html_translation_table()<\/code> Working Examples<\/h3>\n<h4>1. Translation Table Example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nvar_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">array(1510) {\n [\"\n\"]=&gt;\n string(9) \"&amp;NewLine;\"\n [\"!\"]=&gt;\n string(6) \"&amp;excl;\"\n [\"\"\"]=&gt;\n string(6) \"&amp;quot;\"\n [\"#\"]=&gt;\n string(5) \"&amp;num;\"\n [\"$\"]=&gt;\n string(8) \"&amp;dollar;\"\n [\"%\"]=&gt;\n string(8) \"&amp;percnt;\"\n [\"&amp;\"]=&gt;\n string(5) \"&amp;amp;\"\n [\"'\"]=&gt;\n string(6) \"&amp;apos;\"\n \/\/ ...\n}<\/code><\/pre>\n<h3>Changelog for PHP get_html_translation_table()<\/code> Function<\/h3>\n<p><strong>5.4.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to UTF-8. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The constants <code>ENT_HTML401<\/code>, <code>ENT_XML1<\/code>, <code>ENT_XHTML<\/code> and <code>ENT_HTML5<\/code> were added. <\/p>\n<p><strong>5.3.4 \u2014 <\/strong> The <code class=\"parameter\">encoding<\/code> parameter was added. <\/p>\n<h3>Important Points about PHP <code>get_html_translation_table()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Special characters can be encoded in several ways. E.g. <strong>&#8220;<\/strong> can be encoded as <strong>&amp;quot;<\/strong>, <strong>&amp;#34;<\/strong> or <strong>&amp;#x22<\/strong>. <code>get_html_translation_table()<\/code> returns only the form used by <code>htmlspecialchars()<\/code> and <code>htmlentities()<\/code>. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: kevin<\/p>\n<pre><code class=\"lang-php\">Be careful using get_html_translation_table() in a loop, as it's very slow.<\/code><\/pre>\n<p>Contributed By: michael dot genesis<\/p>\n<pre><code class=\"lang-php\">The fact that MS-word and some other sources use CP-1252, and that it is so close to Latin1 ('ISO-8859-1') causes a lot of confusion. What confused me the most was finding that mySQL uses CP-1252 by default. \n \nYou may run into trouble if you find yourself tempted to do something like this: \n&lt;?php \n    $trans[chr(149)] = '&amp;bull;';    \/\/ Bullet \n    $trans[chr(150)] = '&amp;ndash;';    \/\/ En Dash \n    $trans[chr(151)] = '&amp;mdash;';    \/\/ Em Dash \n    $trans[chr(152)] = '&amp;tilde;';    \/\/ Small Tilde \n    $trans[chr(153)] = '&amp;trade;';    \/\/ Trade Mark Sign \n?&gt; \n \nDon't do it. DON'T DO IT! \n \nYou can use: \n&lt;?php \n    $translationTable = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'WINDOWS-1252'); \n?&gt; \n \nor just convert directly: \n&lt;?php \n    $output = htmlentities($input, ENT_NOQUOTES, 'WINDOWS-1252'); \n?&gt; \n \nBut your web page is probably encoded UTF-8, and you probably don't really want CP-1252 text flying around, so fix the character encoding first: \n&lt;?php \n    $output = mb_convert_encoding($input, 'UTF-8', 'WINDOWS-1252'); \n    $ouput = htmlentities($output); \n?&gt;<\/code><\/pre>\n<h2 id=\"hebrev\">PHP <code>hebrev()<\/code> Function<\/h2>\n<h3>What does <code>hebrev()<\/code> do?<\/h3>\n<p>The PHP <code><code>hebrev()<\/code><\/code> function will convert logical Hebrew text to visual text.<\/p>\n<h3>PHP <code>hebrev()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> hebrev ( string $hebrew_text [, int $max_chars_per_line = 0 ] ) : string<\/code><\/pre>\n<h3>PHP <code>hebrev()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>hebrew_text<\/code> \u2014 A Hebrew input string. <\/p>\n<\/li>\n<li>\n<p><code>max_chars_per_line<\/code> \u2014 This optional parameter indicates maximum number of characters per line that will be returned. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>hebrev()<\/code> Return Value<\/h3>\n<p>The PHP <code>hebrev()<\/code> function returns the visual string.<\/p>\n<h2 id=\"hebrevc\">PHP <code>hebrevc()<\/code> Function<\/h2>\n<h3>What does <code>hebrevc()<\/code> do?<\/h3>\n<p>The PHP <code><code>hebrevc()<\/code><\/code> function will convert logical Hebrew text to visual text with newline conversion.<\/p>\n<h3>PHP <code>hebrevc()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> hebrevc ( string $hebrew_text [, int $max_chars_per_line = 0 ] ) : string<\/code><\/pre>\n<h3>PHP <code>hebrevc()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>hebrew_text<\/code> \u2014 A Hebrew input string. <\/p>\n<\/li>\n<li>\n<p><code>max_chars_per_line<\/code> \u2014 This optional parameter indicates maximum number of characters per line that will be returned. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>hebrevc()<\/code> Return Value<\/h3>\n<p>The PHP <code>hebrevc()<\/code> function returns the visual string.<\/p>\n<h2 id=\"hex2bin\">PHP <code>hex2bin()<\/code> Function<\/h2>\n<h3>What does <code>hex2bin()<\/code> do?<\/h3>\n<p>The PHP <code><code>hex2bin()<\/code><\/code> function will decodes a hexadecimally encoded binary string.<\/p>\n<h3>PHP <code>hex2bin()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> hex2bin ( string $data ) : string<\/code><\/pre>\n<h3>PHP <code>hex2bin()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>data<\/code> \u2014 Hexadecimal representation of data. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>hex2bin()<\/code> Return Value<\/h3>\n<p>The PHP <code>hex2bin()<\/code> function returns the binary representation of the given data or <code>FALSE<\/code> on failure.<\/p>\n<h3>PHP <code>hex2bin()<\/code> Working Examples<\/h3>\n<h4>1. hex2bin() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$hex = hex2bin(\"6578616d706c65206865782064617461\");\nvar_dump($hex);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(16) \"example hex data\"<\/code><\/pre>\n<h3>Changelog for PHP hex2bin()<\/code> Function<\/h3>\n<p><strong>5.5.1 \u2014 <\/strong> A warning is thrown if the input string is invalid hexadecimal string. <\/p>\n<p><strong>5.4.4 \u2014 <\/strong> A warning is thrown if the input string is of odd length. In PHP 5.4.0 the string was silently accepted, but the last byte was truncated. <\/p>\n<h3>Important Points about PHP <code>hex2bin()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> This function does <strong>NOT<\/strong> convert a hexadecimal number to a binary number. This can be done using the <code>base_convert()<\/code> function. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Anonymous<\/p>\n<pre><code class=\"lang-php\">The function hex2bin does not exist in PHP5.\nYou can use 'pack' instead :\n$binary_string = pack(\"H*\" , $hex_string);<\/code><\/pre>\n<h2 id=\"html_entity_decode\">PHP <code>html_entity_decode()<\/code> Function<\/h2>\n<h3>What does <code>html_entity_decode()<\/code> do?<\/h3>\n<p>The PHP <code><code>html_entity_decode()<\/code><\/code> function will convert HTML entities to their corresponding characters.<\/p>\n<h3>PHP <code>html_entity_decode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> html_entity_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get(\"default_charset\") ]] ) : string<\/code><\/pre>\n<h3>PHP <code>html_entity_decode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>flags<\/code> \u2014 A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is ENT_COMPAT | ENT_HTML401. <\/p>\n<\/li>\n<li>\n<p><code>encoding<\/code> \u2014 An optional argument defining the encoding used when converting characters. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>html_entity_decode()<\/code> Return Value<\/h3>\n<p>The PHP <code>html_entity_decode()<\/code> function returns the decoded string.<\/p>\n<h3>PHP <code>html_entity_decode()<\/code> Working Examples<\/h3>\n<h4>1. Decoding HTML entities<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$orig = \"I'll \\\"walk\\\" the &lt;b&gt;dog&lt;\/b&gt; now\";\n$a = htmlentities($orig);\n$b = html_entity_decode($a);\necho $a; \/\/ I'll &amp;quot;walk&amp;quot; the &amp;lt;b&amp;gt;dog&amp;lt;\/b&amp;gt; now\necho $b; \/\/ I'll \"walk\" the &lt;b&gt;dog&lt;\/b&gt; now\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP html_entity_decode()<\/code> Function<\/h3>\n<p><strong>5.6.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to be the value of the default_charset configuration option. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> Default encoding changed from ISO-8859-1 to UTF-8. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The constants <code>ENT_HTML401<\/code>, <code>ENT_XML1<\/code>, <code>ENT_XHTML<\/code> and <code>ENT_HTML5<\/code> were added. <\/p>\n<h3>Important Points about PHP <code>html_entity_decode()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> You might wonder why trim(html_entity_decode(&#8216;&amp;nbsp;&#8217;)); doesn&#8217;t reduce the string to an empty string, that&#8217;s because the &#8216;&amp;nbsp;&#8217; entity is not ASCII code 32 (which is stripped by <code>trim()<\/code>) but ASCII code 160 (0xa0) in the default ISO 8859-1 encoding. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Martin<\/p>\n<pre><code class=\"lang-php\">If you need something that converts &amp;#[0-9]+ entities to UTF-8, this is simple and works: \n \n&lt;?php \n\/* Entity crap. \/ \n$input = \"Fovi&amp;#269;\"; \n \n$output = preg_replace_callback(\"\/(&amp;#[0-9]+;)\/\", function($m) { return mb_convert_encoding($m[1], \"UTF-8\", \"HTML-ENTITIES\"); }, $input); \n \n\/* Plain UTF-8. *\/ \necho $output; \n?&gt;<\/code><\/pre>\n<p>Contributed By: txnull<\/p>\n<pre><code class=\"lang-php\">Use the following to decode all entities:\n&lt;?php html_entity_decode($string, ENT_QUOTES | ENT_XML1, 'UTF-8') ?&gt;\nI've checked these special entities: \n- double quotes (&amp;#34;)\n- single quotes (&amp;#39; and &amp;apos;) \n- non printable chars (e.g. &amp;#13;)\nWith other $flags some or all won't be decoded.\nIt seems that ENT_XML1 and ENT_XHTML are identical when decoding.<\/code><\/pre>\n<h2 id=\"htmlentities\">PHP <code>htmlentities()<\/code> Function<\/h2>\n<h3>What does <code>htmlentities()<\/code> do?<\/h3>\n<p>The PHP <code><code>htmlentities()<\/code><\/code> function will convert all applicable characters to HTML entities.<\/p>\n<h3>PHP <code>htmlentities()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get(\"default_charset\") [, bool $double_encode = TRUE ]]] ) : string<\/code><\/pre>\n<h3>PHP <code>htmlentities()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>flags<\/code> \u2014 A bitmask of one or more of the following flags, which specify how to handle quotes, invalid code unit sequences and the used document type. The default is ENT_COMPAT | ENT_HTML401. <\/p>\n<\/li>\n<li>\n<p><code>encoding<\/code> \u2014 An optional argument defining the encoding used when converting characters. <\/p>\n<\/li>\n<li>\n<p><code>double_encode<\/code> \u2014 When double_encode is turned off PHP will not encode existing html entities. The default is to convert everything. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>htmlentities()<\/code> Return Value<\/h3>\n<p>The PHP <code>htmlentities()<\/code> function returns the encoded string.<\/p>\n<h3>PHP <code>htmlentities()<\/code> Working Examples<\/h3>\n<h4>1. A htmlentities() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"A 'quote' is &lt;b&gt;bold&lt;\/b&gt;\";\n\/\/ Outputs: A 'quote' is &amp;lt;b&amp;gt;bold&amp;lt;\/b&amp;gt;\necho htmlentities($str);\n\/\/ Outputs: A &amp;#039;quote&amp;#039; is &amp;lt;b&amp;gt;bold&amp;lt;\/b&amp;gt;\necho htmlentities($str, ENT_QUOTES);\n?&gt;<\/code><\/pre>\n<h4>2. Usage of ENT_IGNORE<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"\\x8F!!!\";\n\/\/ Outputs an empty string\necho htmlentities($str, ENT_QUOTES, \"UTF-8\");\n\/\/ Outputs \"!!!\"\necho htmlentities($str, ENT_QUOTES | ENT_IGNORE, \"UTF-8\");\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP htmlentities()<\/code> Function<\/h3>\n<p><strong>5.6.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to be the value of the default_charset configuration option. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to UTF-8. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The constants <code>ENT_SUBSTITUTE<\/code>, <code>ENT_DISALLOWED<\/code>, <code>ENT_HTML401<\/code>, <code>ENT_XML1<\/code>, <code>ENT_XHTML<\/code> and <code>ENT_HTML5<\/code> were added. <\/p>\n<p><strong>5.3.0 \u2014 <\/strong> The constant <code>ENT_IGNORE<\/code> was added. <\/p>\n<p><strong>5.2.3 \u2014 <\/strong> The <code class=\"parameter\">double_encode<\/code> parameter was added. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Sijmen Ruwhof<\/p>\n<pre><code class=\"lang-php\">An important note below about using this function to secure your application against Cross Site Scripting (XSS) vulnerabilities.\nWhen printing user input in an attribute of an HTML tag, the default configuration of htmlEntities() doesn't protect you against XSS, when using single quotes to define the border of the tag's attribute-value. XSS is then possible by injecting a single quote:\n&lt;?php\n$_GET['a'] = \"#000' onload='alert(document.cookie)\";\n?&gt;\nXSS possible (insecure):\n&lt;?php\n$href = htmlEntities($_GET['a']);\nprint \"&lt;body bgcolor='$href'&gt;\"; # results in: &lt;body bgcolor='#000' onload='alert(document.cookie)'&gt;\n?&gt;\nUse the 'ENT_QUOTES' quote style option, to ensure no XSS is possible and your application is secure:\n&lt;?php\n$href = htmlEntities($_GET['a'], ENT_QUOTES);\nprint \"&lt;body bgcolor='$href'&gt;\"; # results in: &lt;body bgcolor='#000&amp;#039; onload=&amp;#039;alert(document.cookie)'&gt;\n?&gt;\nThe 'ENT_QUOTES' option doesn't protect you against javascript evaluation in certain tag's attributes, like the 'href' attribute of the 'a' tag. When clicked on the link below, the given JavaScript will get executed:\n&lt;?php\n$_GET['a'] = 'javascript:alert(document.cookie)';\n$href = htmlEntities($_GET['a'], ENT_QUOTES);\nprint \"&lt;a href='$href'&gt;link&lt;\/a&gt;\"; # results in: &lt;a href='javascript:alert(document.cookie)'&gt;link&lt;\/a&gt;\n?&gt;<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">I've seen lots of functions to convert all the entities, but I needed to do a fulltext search in a db field that had named entities instead of numeric entities (edited by tinymce), so I searched the tinymce source and found a string with the value-&gt;entity mapping. So, i wrote the following function to encode the user's query with named entities.\nThe string I used is different of the original, because i didn't want to convert ' or \". The string is too long, so I had to cut it. To get the original check TinyMCE source and search for nbsp or other entity ;)\n&lt;?php\n$entities_unmatched = explode(',', '160,nbsp,161,iexcl,162,cent, [...] ');\n$even = 1;\nforeach($entities_unmatched as $c) {\n    if($even) {\n        $ord = $c;\n    } else {\n        $entities_table[$ord] = $c;\n    }\n    $even = 1 - $even;\n}\nfunction encode_named_entities($str) {\n    global $entities_table;\n    \n    $encoded_str = '';\n    for($i = 0; $i &lt; strlen($str); $i++) {\n        $ent = @$entities_table[ord($str{$i})];\n        if($ent) {\n            $encoded_str .= \"&amp;$ent;\";\n        } else {\n            $encoded_str .= $str{$i};\n        }\n    }\n    return $encoded_str;\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: n<\/p>\n<pre><code class=\"lang-php\">Html entities does not encode all unicode characters. It encodes what it can [all of latin1], and the others slip through. &amp;#1033; is the nasty I use. I have searched for a function which encodes everything, but in the end I wrote this. This is as simple as I can get it. Consult an ansii table to custom include\/omit chars you want\/don't. I'm sure it's not that fast.\n\/\/ Unicode-proof htmlentities. \n\/\/ Returns 'normal' chars as chars and weirdos as numeric html entites.\nfunction superentities( $str ){\n    \/\/ get rid of existing entities else double-escape\n    $str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8'); \n    $ar = preg_split('\/(?&lt;!^)(?!$)\/u', $str );  \/\/ return array of every multi-byte character\n    foreach ($ar as $c){\n        $o = ord($c);\n        if ( (strlen($c) &gt; 1) || \/* multi-byte [unicode] *\/\n            ($o &lt;32 || $o &gt; 126) || \/* &lt;- control \/ latin weirdos -&gt; *\/\n            ($o &gt;33 &amp;&amp; $o &lt; 40) ||\/* quotes + ambersand *\/\n            ($o &gt;59 &amp;&amp; $o &lt; 63) \/* html *\/\n        ) {\n            \/\/ convert to numeric entity\n            $c = mb_encode_numericentity($c,array (0x0, 0xffff, 0, 0xffff), 'UTF-8');\n        }\n        $str2 .= $c;\n    }\n    return $str2;\n}<\/code><\/pre>\n<p>Contributed By: phil<\/p>\n<pre><code class=\"lang-php\">The following will make a string completely safe for XML:\n&lt;?php\nfunction philsXMLClean($strin) {\n        $strout = null;\n        for ($i = 0; $i &lt; strlen($strin); $i++) {\n                $ord = ord($strin[$i]);\n                if (($ord &gt; 0 &amp;&amp; $ord &lt; 32) || ($ord &gt;= 127)) {\n                        $strout .= \"&amp;amp;#{$ord};\";\n                }\n                else {\n                        switch ($strin[$i]) {\n                                case '&lt;':\n                                        $strout .= '&amp;lt;';\n                                        break;\n                                case '&gt;':\n                                        $strout .= '&amp;gt;';\n                                        break;\n                                case '&amp;':\n                                        $strout .= '&amp;amp;';\n                                        break;\n                                case '\"':\n                                        $strout .= '&amp;quot;';\n                                        break;\n                                default:\n                                        $strout .= $strin[$i];\n                        }\n                }\n        }\n        return $strout;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"htmlspecialchars\">PHP <code>htmlspecialchars()<\/code> Function<\/h2>\n<h3>What does <code>htmlspecialchars()<\/code> do?<\/h3>\n<p>The PHP <code><code>htmlspecialchars()<\/code><\/code> function will convert special characters to HTML entities.<\/p>\n<h3>PHP <code>htmlspecialchars()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get(\"default_charset\") [, bool $double_encode = TRUE ]]] ) : string<\/code><\/pre>\n<h3>PHP <code>htmlspecialchars()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The string being converted. <\/p>\n<\/li>\n<li>\n<p><code>flags<\/code> \u2014 A bitmask of one or more of the following flags, which specify how to handle quotes, invalid code unit sequences and the used document type. The default is ENT_COMPAT | ENT_HTML401. <\/p>\n<\/li>\n<li>\n<p><code>encoding<\/code> \u2014 An optional argument defining the encoding used when converting characters. <\/p>\n<\/li>\n<li>\n<p><code>double_encode<\/code> \u2014 When double_encode is turned off PHP will not encode existing html entities, the default is to convert everything. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>htmlspecialchars()<\/code> Return Value<\/h3>\n<p>The PHP <code>htmlspecialchars()<\/code> function returns the converted string.<\/p>\n<h3>PHP <code>htmlspecialchars()<\/code> Working Examples<\/h3>\n<h4>1. htmlspecialchars() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$new = htmlspecialchars(\"&lt;a href='test'&gt;Test&lt;\/a&gt;\", ENT_QUOTES);\necho $new; \/\/ &amp;lt;a href=&amp;#039;test&amp;#039;&amp;gt;Test&amp;lt;\/a&amp;gt;\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP htmlspecialchars()<\/code> Function<\/h3>\n<p><strong>5.6.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to be the value of the default_charset configuration option. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The default value for the <code class=\"parameter\">encoding<\/code> parameter was changed to UTF-8. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> The constants <code>ENT_SUBSTITUTE<\/code>, <code>ENT_DISALLOWED<\/code>, <code>ENT_HTML401<\/code>, <code>ENT_XML1<\/code>, <code>ENT_XHTML<\/code> and <code>ENT_HTML5<\/code> were added. <\/p>\n<p><strong>5.3.0 \u2014 <\/strong> The constant <code>ENT_IGNORE<\/code> was added. <\/p>\n<p><strong>5.2.3 \u2014 <\/strong> The <code class=\"parameter\">double_encode<\/code> parameter was added. <\/p>\n<h3>Important Points about PHP <code>htmlspecialchars()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Note that this function does not translate anything beyond what is listed above. For full entity translation, see <code>htmlentities()<\/code>. <\/p>\n<\/li>\n<li>\n<p> In case of an ambiguous <code class=\"parameter\">flags<\/code> value, the following rules apply: <\/p>\n<\/li>\n<li>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Dave<\/p>\n<pre><code class=\"lang-php\">As of PHP 5.4 they changed default encoding from \"ISO-8859-1\" to \"UTF-8\". So if you get null from htmlspecialchars or htmlentities\nwhere you have only set \n&lt;?php\necho htmlspecialchars($string);\necho htmlentities($string);\n?&gt;\nyou can fix it by\n&lt;?php\necho htmlspecialchars($string, ENT_COMPAT,'ISO-8859-1', true);\necho htmlentities($string, ENT_COMPAT,'ISO-8859-1', true);\n?&gt; \nOn linux you can find the scripts you need to fix by\ngrep -Rl \"htmlspecialchars\\\\|htmlentities\" \/path\/to\/php\/scripts\/<\/code><\/pre>\n<p>Contributed By: Mike Robinson<\/p>\n<pre><code class=\"lang-php\">Unfortunately, as far as I can tell, the PHP devs did not provide ANY way to set the default encoding used by htmlspecialchars() or htmlentities(), even though they changed the default encoding in PHP 5.4 (*golf clap for PHP devs*). To save someone the time of trying it, this does not work:\n&lt;?php\nini_set('default_charset', $charset); \/\/ doesn't work.\n?&gt;\nUnfortunately, the only way to not have to explicitly provide the second and third parameter every single time this function is called (which gets extremely tedious) is to write your own function as a wrapper:\n&lt;?php\ndefine('CHARSET', 'ISO-8859-1');\ndefine('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML);\nfunction html($string) {\n    return htmlspecialchars($string, REPLACE_FLAGS, CHARSET);\n}\necho html(\"\u00f1\"); \/\/ works\n?&gt;\nYou can do the same for htmlentities()<\/code><\/pre>\n<p>Contributed By: Thomasvdbulk<\/p>\n<pre><code class=\"lang-php\">I searched for a while for a script, that could see the difference between an html tag and just &lt; and &gt; placed in the text, \nthe reason is that i recieve text from a database,\nwich is inserted by an html form, and contains text and html tags, \nthe text can contain &lt; and &gt;, so does the tags,\nwith htmlspecialchars you can validate your text to XHTML,\nbut you'll also change the tags, like &lt;b&gt; to &amp;lt;b&amp;gt;,\nso i needed a script that could see the difference between those two...\nbut i couldn't find one so i made my own one, \ni havent fully tested it, but the parts i tested worked perfect!\njust for people that were searching for something like this,\nit may looks big, could be done easier, but it works for me, so im happy.\n&lt;?php\nfunction fixtags($text){\n$text = htmlspecialchars($text);\n$text = preg_replace(\"\/=\/\", \"=\\\"\\\"\", $text);\n$text = preg_replace(\"\/&amp;quot;\/\", \"&amp;quot;\\\"\", $text);\n$tags = \"\/&amp;lt;(\\\/|)(\\w*)(\\ |)(\\w*)([\\\\\\=]*)(?|(\\\")\\\"&amp;quot;\\\"|)(?|(.*)?&amp;quot;(\\\")|)([\\ ]?)(\\\/|)&amp;gt;\/i\";\n$replacement = \"&lt;$1$2$3$4$5$6$7$8$9$10&gt;\";\n$text = preg_replace($tags, $replacement, $text);\n$text = preg_replace(\"\/=\\\"\\\"\/\", \"=\", $text);\nreturn $text;\n}\n?&gt;\nan example:\n&lt;?php\n$string = \"\nthis is smaller &lt; than this&lt;br \/&gt; \nthis is greater &gt; than this&lt;br \/&gt;\nthis is the same = as this&lt;br \/&gt;\n&lt;a href=\\\"http:\/\/www.example.com\/example.php?test=test\\\"&gt;This is a link&lt;\/a&gt;&lt;br \/&gt;\n&lt;b&gt;Bold&lt;\/b&gt; &lt;i&gt;italic&lt;\/i&gt; etc...\";\necho fixtags($string);\n?&gt;\nwill echo:\nthis is smaller &amp;lt; than this&lt;br \/&gt; \nthis is greater &amp;gt; than this&lt;br \/&gt; \nthis is the same = as this&lt;br \/&gt; \n&lt;a href=\"http:\/\/www.example.com\/example.php?test=test\"&gt;This is a link&lt;\/a&gt;&lt;br \/&gt; \n&lt;b&gt;Bold&lt;\/b&gt; &lt;i&gt;italic&lt;\/i&gt; etc...\nI hope its helpfull!!<\/code><\/pre>\n<h2 id=\"htmlspecialchars_decode\">PHP <code>htmlspecialchars_decode()<\/code> Function<\/h2>\n<h3>What does <code>htmlspecialchars_decode()<\/code> do?<\/h3>\n<p>The PHP <code><code>htmlspecialchars_decode()<\/code><\/code> function will convert special HTML entities back to characters .<\/p>\n<h3>PHP <code>htmlspecialchars_decode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] ) : string<\/code><\/pre>\n<h3>PHP <code>htmlspecialchars_decode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The string to decode. <\/p>\n<\/li>\n<li>\n<p><code>flags<\/code> \u2014 A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is ENT_COMPAT | ENT_HTML401. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>htmlspecialchars_decode()<\/code> Return Value<\/h3>\n<p>The PHP <code>htmlspecialchars_decode()<\/code> function returns the decoded string.<\/p>\n<h3>PHP <code>htmlspecialchars_decode()<\/code> Working Examples<\/h3>\n<h4>1. A htmlspecialchars_decode() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"&lt;p&gt;this -&amp;gt; &amp;quot;&lt;\/p&gt;\\n\";\necho htmlspecialchars_decode($str);\n\/\/ note that here the quotes aren't converted\necho htmlspecialchars_decode($str, ENT_NOQUOTES);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">&lt;p&gt;this -&gt; \"&lt;\/p&gt;\n&lt;p&gt;this -&gt; &amp;quot;&lt;\/p&gt;<\/code><\/pre>\n<h3>Changelog for PHP htmlspecialchars_decode()<\/code> Function<\/h3>\n<p><strong>5.4.0 \u2014 <\/strong> The constants <code>ENT_HTML401<\/code>, <code>ENT_XML1<\/code>, <code>ENT_XHTML<\/code> and <code>ENT_HTML5<\/code> were added. <\/p>\n<h2 id=\"implode\">PHP <code>implode()<\/code> Function<\/h2>\n<h3>What does <code>implode()<\/code> do?<\/h3>\n<p>The PHP <code><code>implode()<\/code><\/code> function will join array elements with a <code class=\"parameter\">glue<\/code> string.<\/p>\n<h3>PHP <code>implode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> implode ( string $glue , array $pieces ) : string<\/code><\/pre>\n<pre><code class=\"lang-php\"> implode ( array $pieces ) : string<\/code><\/pre>\n<h3>PHP <code>implode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>glue<\/code> \u2014 Defaults to an empty string. <\/p>\n<\/li>\n<li>\n<p><code>pieces<\/code> \u2014 The array of strings to implode. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>implode()<\/code> Return Value<\/h3>\n<p>The PHP <code>implode()<\/code> function returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.<\/p>\n<h3>PHP <code>implode()<\/code> Working Examples<\/h3>\n<h4>1. implode() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$array = array('lastname', 'email', 'phone');\n$comma_separated = implode(\",\", $array);\necho $comma_separated; \/\/ lastname,email,phone\n\/\/ Empty string when using an empty array:\nvar_dump(implode('hello', array())); \/\/ string(0) \"\"\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>implode()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> <code>implode()<\/code> can, for historical reasons, accept its parameters in either order. For consistency with <code>explode()<\/code>, however, it may be less confusing to use the documented order of arguments. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: houston_roadrunner<\/p>\n<pre><code class=\"lang-php\">It should be noted that an array with one or no elements works fine. for example:\n&lt;?php\n    $a1 = array(\"1\",\"2\",\"3\");\n    $a2 = array(\"a\");\n    $a3 = array();\n    \n    echo \"a1 is: '\".implode(\"','\",$a1).\"'&lt;br&gt;\";\n    echo \"a2 is: '\".implode(\"','\",$a2).\"'&lt;br&gt;\";\n    echo \"a3 is: '\".implode(\"','\",$a3).\"'&lt;br&gt;\";\n?&gt;\nwill produce:\n===========\na1 is: '1','2','3'\na2 is: 'a'\na3 is: ''<\/code><\/pre>\n<p>Contributed By: omar dot ajoue<\/p>\n<pre><code class=\"lang-php\">Can also be used for building tags or complex lists, like the following:\n&lt;?php\n$elements = array('a', 'b', 'c');\necho \"&lt;ul&gt;&lt;li&gt;\" . implode(\"&lt;\/li&gt;&lt;li&gt;\", $elements) . \"&lt;\/li&gt;&lt;\/ul&gt;\";\n?&gt;\nThis is just an example, you can create a lot more just finding the right glue! ;)<\/code><\/pre>\n<p>Contributed By: ASchmidt<\/p>\n<pre><code class=\"lang-php\">It's not obvious from the samples, if\/how associative arrays are handled. The \"implode\" function acts on the array \"values\", disregarding any keys:\n&lt;?php\ndeclare(strict_types=1);\n$a = array( 'one','two','three' );\n$b = array( '1st' =&gt; 'four', 'five', '3rd' =&gt; 'six' );\necho implode( ',', $a ),'\/', implode( ',', $b );\n?&gt;\noutputs:\none,two,three\/four,five,six<\/code><\/pre>\n<p>Contributed By: Felix Rauch<\/p>\n<pre><code class=\"lang-php\">It might be worthwhile noting that the array supplied to implode() can contain objects, provided the objects implement the __toString() method.\nExample:\n&lt;?php\nclass Foo\n{\n    protected $title;\n    public function __construct($title)\n    {\n        $this-&gt;title = $title;\n    }\n    public function __toString()\n    {\n        return $this-&gt;title;\n    }\n}\n$array = [\n    new Foo('foo'),\n    new Foo('bar'),\n    new Foo('qux')\n];\necho implode('; ', $array);\n?&gt;\nwill output:\nfoo; bar; qux<\/code><\/pre>\n<p>Contributed By: php.net <\/p>\n<pre><code class=\"lang-php\">Also quite handy in INSERT statements:\n&lt;?php\n   \/\/ array containing data\n   $array = array(\n      \"name\" =&gt; \"John\",\n      \"surname\" =&gt; \"Doe\",\n      \"email\" =&gt; \"j.doe@intelligence.gov\"\n   );\n   \/\/ build query...\n   $sql  = \"INSERT INTO table\";\n   \/\/ implode keys of $array...\n   $sql .= \" (`\".implode(\"`, `\", array_keys($array)).\"`)\";\n   \/\/ implode values of $array...\n   $sql .= \" VALUES ('\".implode(\"', '\", $array).\"') \";\n   \/\/ execute query...\n   $result = mysql_query($sql) or die(mysql_error());\n?&gt;<\/code><\/pre>\n<p>Contributed By: alexey dot klimko<\/p>\n<pre><code class=\"lang-php\">If you want to implode an array of booleans, you will get a strange result:\n&lt;?php\nvar_dump(implode('',array(true, true, false, false, true)));\n?&gt;\nOutput:\nstring(3) \"111\"\nTRUE became \"1\", FALSE became nothing.<\/code><\/pre>\n<p>Contributed By: Anonymous<\/p>\n<pre><code class=\"lang-php\">It may be worth noting that if you accidentally call implode on a string rather than an array, you do NOT get your string back, you get NULL:\n&lt;?php\nvar_dump(implode(':', 'xxxxx'));\n?&gt;\nreturns\nNULL\nThis threw me for a little while.<\/code><\/pre>\n<p>Contributed By: masterandujar<\/p>\n<pre><code class=\"lang-php\">Even handier if you use the following: \n \n&lt;?php \n$id_nums = array(1,6,12,18,24); \n \n$id_nums = implode(\", \", $id_nums); \n                \n$sqlquery = \"Select name,email,phone from usertable where user_id IN ($id_nums)\"; \n \n\/\/ $sqlquery becomes \"Select name,email,phone from usertable where user_id IN (1,6,12,18,24)\" \n?&gt; \n \nBe sure to escape\/sanitize\/use prepared statements if you get the ids from users.<\/code><\/pre>\n<h2 id=\"join\">PHP <code>join()<\/code> Function<\/h2>\n<h3>What does <code>join()<\/code> do?<\/h3>\n<p>The PHP <code><code>join()<\/code><\/code> function will this function is an alias of: <code>implode()<\/code>.<\/p>\n<h3>PHP <code>join()<\/code> Syntax<\/h3>\n<h3>PHP <code>join()<\/code> Parameters<\/h3>\n<ol><\/ol>\n<p>This function does not accept any parameters.<\/p>\n<h2 id=\"lcfirst\">PHP <code>lcfirst()<\/code> Function<\/h2>\n<h3>What does <code>lcfirst()<\/code> do?<\/h3>\n<p>The PHP <code><code>lcfirst()<\/code><\/code> function will make a string&#8217;s first character lowercase.<\/p>\n<h3>PHP <code>lcfirst()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> lcfirst ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>lcfirst()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>lcfirst()<\/code> Return Value<\/h3>\n<p>The PHP <code>lcfirst()<\/code> function returns the resulting string.<\/p>\n<h3>PHP <code>lcfirst()<\/code> Working Examples<\/h3>\n<h4>1. lcfirst() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$foo = 'HelloWorld';\n$foo = lcfirst($foo);             \/\/ helloWorld\n$bar = 'HELLO WORLD!';\n$bar = lcfirst($bar);             \/\/ hELLO WORLD!\n$bar = lcfirst(strtoupper($bar)); \/\/ hELLO WORLD!\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: phpnet<\/p>\n<pre><code class=\"lang-php\">Easiest work-around I've found for &lt;5.3:\n&lt;?php\n$string = \"CamelCase\"\n$string{0} = strtolower($string{0})\necho $string; \/\/ outputs camelCase\n?&gt;<\/code><\/pre>\n<h2 id=\"levenshtein\">PHP <code>levenshtein()<\/code> Function<\/h2>\n<h3>What does <code>levenshtein()<\/code> do?<\/h3>\n<p>The PHP <code><code>levenshtein()<\/code><\/code> function will calculate Levenshtein distance between two strings.<\/p>\n<h3>PHP <code>levenshtein()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> levenshtein ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<pre><code class=\"lang-php\"> levenshtein ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del ) : int<\/code><\/pre>\n<h3>PHP <code>levenshtein()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 One of the strings being evaluated for Levenshtein distance. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 One of the strings being evaluated for Levenshtein distance. <\/p>\n<\/li>\n<li>\n<p><code>cost_ins<\/code> \u2014 Defines the cost of insertion. <\/p>\n<\/li>\n<li>\n<p><code>cost_rep<\/code> \u2014 Defines the cost of replacement. <\/p>\n<\/li>\n<li>\n<p><code>cost_del<\/code> \u2014 Defines the cost of deletion. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>levenshtein()<\/code> Return Value<\/h3>\n<p>The PHP <code>levenshtein()<\/code> function returns the Levenshtein-Distance between the two argument strings or -1, if one of the argument strings is longer than the limit of 255 characters.<\/p>\n<h3>PHP <code>levenshtein()<\/code> Working Examples<\/h3>\n<h4>1. levenshtein() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ input misspelled word\n$input = 'carrrot';\n\/\/ array of words to check against\n$words  = array('apple','pineapple','banana','orange',\n                'radish','carrot','pea','bean','potato');\n\/\/ no shortest distance found, yet\n$shortest = -1;\n\/\/ loop through words to find the closest\nforeach ($words as $word) {\n    \/\/ calculate the distance between the input word,\n    \/\/ and the current word\n    $lev = levenshtein($input, $word);\n    \/\/ check for an exact match\n    if ($lev == 0) {\n        \/\/ closest word is this one (exact match)\n        $closest = $word;\n        $shortest = 0;\n        \/\/ break out of the loop; we've found an exact match\n        break;\n    }\n    \/\/ if this distance is less than the next found shortest\n    \/\/ distance, OR if a next shortest word has not yet been found\n    if ($lev &lt;= $shortest || $shortest &lt; 0) {\n        \/\/ set the closest match, and shortest distance\n        $closest  = $word;\n        $shortest = $lev;\n    }\n}\necho \"Input word: $input\\n\";\nif ($shortest == 0) {\n    echo \"Exact match found: $closest\\n\";\n} else {\n    echo \"Did you mean: $closest?\\n\";\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Input word: carrrot\nDid you mean: carrot?<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: luciole75w<\/p>\n<pre><code class=\"lang-php\">The levenshtein function processes each byte of the input string individually. Then for multibyte encodings, such as UTF-8, it may give misleading results.\nExample with a french accented word :\n- levenshtein('notre', 'votre') = 1\n- levenshtein('notre', 'n\u00f4tre') = 2 (huh ?!)\nYou can easily find a multibyte compliant PHP implementation of the levenshtein function but it will be of course much slower than the C implementation.\nAnother option is to convert the strings to a single-byte (lossless) encoding so that they can feed the fast core levenshtein function.\nHere is the conversion function I used with a search engine storing UTF-8 strings, and a quick benchmark. I hope it will help.\n&lt;?php\n\/\/ Convert an UTF-8 encoded string to a single-byte string suitable for\n\/\/ functions such as levenshtein.\n\/\/ \n\/\/ The function simply uses (and updates) a tailored dynamic encoding\n\/\/ (in\/out map parameter) where non-ascii characters are remapped to\n\/\/ the range [128-255] in order of appearance.\n\/\/\n\/\/ Thus it supports up to 128 different multibyte code points max over\n\/\/ the whole set of strings sharing this encoding.\n\/\/\nfunction utf8_to_extended_ascii($str, &amp;$map)\n{\n    \/\/ find all multibyte characters (cf. utf-8 encoding specs)\n    $matches = array();\n    if (!preg_match_all('\/[\\xC0-\\xF7][\\x80-\\xBF]+\/', $str, $matches))\n        return $str; \/\/ plain ascii string\n    \n    \/\/ update the encoding map with the characters not already met\n    foreach ($matches[0] as $mbc)\n        if (!isset($map[$mbc]))\n            $map[$mbc] = chr(128 + count($map));\n    \n    \/\/ finally remap non-ascii characters\n    return strtr($str, $map);\n}\n\/\/ Didactic example showing the usage of the previous conversion function but,\n\/\/ for better performance, in a real application with a single input string\n\/\/ matched against many strings from a database, you will probably want to\n\/\/ pre-encode the input only once.\n\/\/\nfunction levenshtein_utf8($s1, $s2)\n{\n    $charMap = array();\n    $s1 = utf8_to_extended_ascii($s1, $charMap);\n    $s2 = utf8_to_extended_ascii($s2, $charMap);\n    \n    return levenshtein($s1, $s2);\n}\n?&gt;\nResults (for about 6000 calls)\n- reference time core C function (single-byte) : 30 ms\n- utf8 to ext-ascii conversion + core function : 90 ms\n- full php implementation : 3000 ms<\/code><\/pre>\n<p>Contributed By: paulrowe<\/p>\n<pre><code class=\"lang-php\">[EDITOR'S NOTE: original post and 2 corrections combined into 1 -- mgf] \n \nHere is an implementation of the Levenshtein Distance calculation that only uses a one-dimensional array and doesn't have a limit to the string length. This implementation was inspired by maze generation algorithms that also use only one-dimensional arrays. \n \nI have tested this function with two 532-character strings and it completed in 0.6-0.8 seconds. \n \n&lt;?php \n\/* \n* This function starts out with several checks in an attempt to save time. \n*   1.  The shorter string is always used as the \"right-hand\" string (as the size of the array is based on its length).  \n*   2.  If the left string is empty, the length of the right is returned. \n*   3.  If the right string is empty, the length of the left is returned. \n*   4.  If the strings are equal, a zero-distance is returned. \n*   5.  If the left string is contained within the right string, the difference in length is returned. \n*   6.  If the right string is contained within the left string, the difference in length is returned. \n* If none of the above conditions were met, the Levenshtein algorithm is used. \n*\/ \nfunction LevenshteinDistance($s1, $s2) \n{ \n  $sLeft = (strlen($s1) &gt; strlen($s2)) ? $s1 : $s2; \n  $sRight = (strlen($s1) &gt; strlen($s2)) ? $s2 : $s1; \n  $nLeftLength = strlen($sLeft); \n  $nRightLength = strlen($sRight); \n  if ($nLeftLength == 0) \n    return $nRightLength; \n  else if ($nRightLength == 0) \n    return $nLeftLength; \n  else if ($sLeft === $sRight) \n    return 0; \n  else if (($nLeftLength &lt; $nRightLength) &amp;&amp; (strpos($sRight, $sLeft) !== FALSE)) \n    return $nRightLength - $nLeftLength; \n  else if (($nRightLength &lt; $nLeftLength) &amp;&amp; (strpos($sLeft, $sRight) !== FALSE)) \n    return $nLeftLength - $nRightLength; \n  else { \n    $nsDistance = range(1, $nRightLength + 1); \n    for ($nLeftPos = 1; $nLeftPos &lt;= $nLeftLength; ++$nLeftPos) \n    { \n      $cLeft = $sLeft[$nLeftPos - 1]; \n      $nDiagonal = $nLeftPos - 1; \n      $nsDistance[0] = $nLeftPos; \n      for ($nRightPos = 1; $nRightPos &lt;= $nRightLength; ++$nRightPos) \n      { \n        $cRight = $sRight[$nRightPos - 1]; \n        $nCost = ($cRight == $cLeft) ? 0 : 1; \n        $nNewDiagonal = $nsDistance[$nRightPos]; \n        $nsDistance[$nRightPos] = \n          min($nsDistance[$nRightPos] + 1, \n              $nsDistance[$nRightPos - 1] + 1, \n              $nDiagonal + $nCost); \n        $nDiagonal = $nNewDiagonal; \n      } \n    } \n    return $nsDistance[$nRightLength]; \n  } \n} \n?&gt;<\/code><\/pre>\n<h2 id=\"localeconv\">PHP <code>localeconv()<\/code> Function<\/h2>\n<h3>What does <code>localeconv()<\/code> do?<\/h3>\n<p>The PHP <code><code>localeconv()<\/code><\/code> function will give you an associative array containing localized numeric and monetary formatting information.<\/p>\n<h3>PHP <code>localeconv()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> localeconv ( void ) : array<\/code><\/pre>\n<h3>PHP <code>localeconv()<\/code> Parameters<\/h3>\n<ol><\/ol>\n<p>This function does not accept any parameters.<\/p>\n<h3>PHP <code>localeconv()<\/code> Return Value<\/h3>\n<p>The PHP <code>localeconv()<\/code> function returns data based upon the current locale as set by <code>setlocale()<\/code>. The associative array that is returned contains the following fields:<\/p>\n<h3>PHP <code>localeconv()<\/code> Working Examples<\/h3>\n<h4>1. localeconv() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nif (false !== setlocale(LC_ALL, 'nl_NL.UTF-8@euro')) {\n    $locale_info = localeconv();\n    print_r($locale_info);\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Array\n(\n [decimal_point] =&gt; .\n [thousands_sep] =&gt;\n [int_curr_symbol] =&gt; EUR\n [currency_symbol] =&gt; \u20ac\n [mon_decimal_point] =&gt; ,\n [mon_thousands_sep] =&gt;\n [positive_sign] =&gt;\n [negative_sign] =&gt; -\n [int_frac_digits] =&gt; 2\n [frac_digits] =&gt; 2\n [p_cs_precedes] =&gt; 1\n [p_sep_by_space] =&gt; 1\n [n_cs_precedes] =&gt; 1\n [n_sep_by_space] =&gt; 1\n [p_sign_posn] =&gt; 1\n [n_sign_posn] =&gt; 2\n [grouping] =&gt; Array\n (\n )\n [mon_grouping] =&gt; Array\n (\n [0] =&gt; 3\n [1] =&gt; 3\n )\n)<\/code><\/pre>\n<h2 id=\"ltrim\">PHP <code>ltrim()<\/code> Function<\/h2>\n<h3>What does <code>ltrim()<\/code> do?<\/h3>\n<p>The PHP <code><code>ltrim()<\/code><\/code> function will strip whitespace (or other characters) from the beginning of a string.<\/p>\n<h3>PHP <code>ltrim()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> ltrim ( string $str [, string $character_mask ] ) : string<\/code><\/pre>\n<h3>PHP <code>ltrim()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>character_mask<\/code> \u2014 You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>ltrim()<\/code> Return Value<\/h3>\n<p>The PHP <code>ltrim()<\/code> function returns a string with whitespace stripped from the beginning of <code class=\"parameter\">str<\/code>. Without the second parameter, <code>ltrim()<\/code> will strip these characters:<\/p>\n<h3>PHP <code>ltrim()<\/code> Working Examples<\/h3>\n<h4>1. Usage example of ltrim()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = \"\\t\\tThese are a few words :) ...  \";\n$binary = \"\\x09Example string\\x0A\";\n$hello  = \"Hello World\";\nvar_dump($text, $binary, $hello);\nprint \"\\n\";\n$trimmed = ltrim($text);\nvar_dump($trimmed);\n$trimmed = ltrim($text, \" \\t.\");\nvar_dump($trimmed);\n$trimmed = ltrim($hello, \"Hdle\");\nvar_dump($trimmed);\n\/\/ trim the ASCII control characters at the beginning of $binary\n\/\/ (from 0 to 31 inclusive)\n$clean = ltrim($binary, \"\\x00..\\x1F\");\nvar_dump($clean);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(32) \" These are a few words :) ... \"\nstring(16) \" Example string\n\"\nstring(11) \"Hello World\"\nstring(30) \"These are a few words :) ... \"\nstring(30) \"These are a few words :) ... \"\nstring(7) \"o World\"\nstring(15) \"Example string\n\"<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: tavi undersc 10 from yahoocom<\/p>\n<pre><code class=\"lang-php\">When using a $character_mask the trimming stops at the first character that is not on that mask.\nSo in the $string = \"Hello world\" example with $character_mask = \"Hdle\", ltrim($hello, $character_mask) goes like this:\n1. Check H from \"Hello world\" =&gt; it is in the $character_mask, so remove it\n2. Check e from \"ello world\" =&gt; it is in the $character_mask, so remove it\n3. Check l from \"llo world\" =&gt; it is in the $character_mask, so remove it\n4. Check l from \"lo world\" =&gt; it is in the $character_mask, so remove it\n5. Check o from \"o world\" =&gt; it is NOT in the $character_mask, exit the function\nRemaining string is \"o world\".\nI hope it helps someone as I had a confusing moment with this function.<\/code><\/pre>\n<h2 id=\"md5\">PHP <code>md5()<\/code> Function<\/h2>\n<h3>What does <code>md5()<\/code> do?<\/h3>\n<p>The PHP <code><code>md5()<\/code><\/code> function will give you that hash.<\/p>\n<h3>PHP <code>md5()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> md5 ( string $str [, bool $raw_output = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>md5()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string. <\/p>\n<\/li>\n<li>\n<p><code>raw_output<\/code> \u2014 If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>md5()<\/code> Return Value<\/h3>\n<p>The PHP <code>md5()<\/code> function returns the hash as a 32-character hexadecimal number.<\/p>\n<h3>PHP <code>md5()<\/code> Working Examples<\/h3>\n<h4>1. A md5() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = 'apple';\nif (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {\n    echo \"Would you like a green or red apple?\";\n}\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>md5()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See the Password Hashing FAQ for details and best practices. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Ray.Paseur sometimes uses Gmail<\/p>\n<pre><code class=\"lang-php\">Md5('240610708') == md5('QNKCDZO')\nThis comparison is true because both md5() hashes start '0e' so PHP type juggling understands these strings to be scientific notation.  By definition, zero raised to any power is zero.<\/code><\/pre>\n<h2 id=\"md5_file\">PHP <code>md5_file()<\/code> Function<\/h2>\n<h3>What does <code>md5_file()<\/code> do?<\/h3>\n<p>The PHP <code><code>md5_file()<\/code><\/code> function will give you that hash. The hash is a 32-character hexadecimal number.<\/p>\n<h3>PHP <code>md5_file()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> md5_file ( string $filename [, bool $raw_output = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>md5_file()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>filename<\/code> \u2014 The filename <\/p>\n<\/li>\n<li>\n<p><code>raw_output<\/code> \u2014 When TRUE, returns the digest in raw binary format with a length of 16. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>md5_file()<\/code> Return Value<\/h3>\n<p>The PHP <code>md5_file()<\/code> function returns a string on success, <code>FALSE<\/code> otherwise.<\/p>\n<h3>PHP <code>md5_file()<\/code> Working Examples<\/h3>\n<h4>1. Usage example of md5_file()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$file = 'php-5.3.0alpha2-Win32-VC9-x64.zip';\necho 'MD5 file hash of ' . $file . ': ' . md5_file($file);\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP md5_file()<\/code> Function<\/h3>\n<p><strong>5.1.0 \u2014 <\/strong> Changed the function to use the streams API. It means that you can use it with wrappers, like md5_file(&#8216;http:\/\/example.com\/..&#8217;) <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Chris<\/p>\n<pre><code class=\"lang-php\">If you just need to find out if two files are identical, comparing file hashes can be inefficient, especially on large files.  There's no reason to read two whole files and do all the math if the second byte of each file is different.  If you don't need to store the hash value for later use, there may not be a need to calculate the hash value just to compare files.  This can be much faster:\n&lt;?php\ndefine('READ_LEN', 4096);\nif(files_identical('file1.txt', 'file2.txt'))\n    echo 'files identical';\nelse\n    echo 'files not identical';\n\/\/   pass two file names\n\/\/   returns TRUE if files are the same, FALSE otherwise\nfunction files_identical($fn1, $fn2) {\n    if(filetype($fn1) !== filetype($fn2))\n        return FALSE;\n    if(filesize($fn1) !== filesize($fn2))\n        return FALSE;\n    if(!$fp1 = fopen($fn1, 'rb'))\n        return FALSE;\n    if(!$fp2 = fopen($fn2, 'rb')) {\n        fclose($fp1);\n        return FALSE;\n    }\n    $same = TRUE;\n    while (!feof($fp1) and !feof($fp2))\n        if(fread($fp1, READ_LEN) !== fread($fp2, READ_LEN)) {\n            $same = FALSE;\n            break;\n        }\n    if(feof($fp1) !== feof($fp2))\n        $same = FALSE;\n    fclose($fp1);\n    fclose($fp2);\n    return $same;\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: lukasamd<\/p>\n<pre><code class=\"lang-php\">It's faster to use md5sum than openssl md5:\n&lt;?php\n$begin = microtime(true);\n$file_path = '..\/backup_file1.tar.gz';\n$result = explode(\"  \", exec(\"md5sum $file_path\"));\necho \"Hash = \".$result[0].\"&lt;br \/&gt;\";\n# Here 7 other big files (20-300 MB)\n$end = microtime(true) - $begin;\necho \"Time = $end\";\n# Time = 4.4475841522217 \n#Method with openssl\n# Time = 12.1463856900543\n?&gt;\nAbout 3x faster<\/code><\/pre>\n<h2 id=\"metaphone\">PHP <code>metaphone()<\/code> Function<\/h2>\n<h3>What does <code>metaphone()<\/code> do?<\/h3>\n<p>The PHP <code><code>metaphone()<\/code><\/code> function will calculates the metaphone key of <code class=\"parameter\">str<\/code>.<\/p>\n<h3>PHP <code>metaphone()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> metaphone ( string $str [, int $phonemes = 0 ] ) : string<\/code><\/pre>\n<h3>PHP <code>metaphone()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>phonemes<\/code> \u2014 This parameter restricts the returned metaphone key to phonemes characters in length. The default value of 0 means no restriction. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>metaphone()<\/code> Return Value<\/h3>\n<p>The PHP <code>metaphone()<\/code> function returns the metaphone key as a string, or <code>FALSE<\/code> on failure.<\/p>\n<h3>PHP <code>metaphone()<\/code> Working Examples<\/h3>\n<h4>1. metaphone() basic example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nvar_dump(metaphone('programming'));\nvar_dump(metaphone('programmer'));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(7) \"PRKRMNK\"\nstring(6) \"PRKRMR\"<\/code><\/pre>\n<h4>2. Using the phonemes parameter<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nvar_dump(metaphone('programming', 5));\nvar_dump(metaphone('programmer', 5));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(5) \"PRKRM\"\nstring(5) \"PRKRM\"<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: mail<\/p>\n<pre><code class=\"lang-php\">You can use the metaphone function quite effectively with phrases by taking the levenshtein distances between two metaphone codes, and then taking this as a percentage of the length of the original metaphone code. thus you can define a percentage error, (say 20%) and accept only matches that are closer than that. i've found this works quite effectively in a function i am using on my website where an album name that the user entered is verified against existing album names that may be similar. this is also an excellent way of people being able to vaguely remember a phrase and get several suggestions out of the database. so you could type \"i stiched nine times\" with an error percentage of, say, 50 and still get 'a stitch in time saves nine' back as a match.<\/code><\/pre>\n<p>Contributed By: php<\/p>\n<pre><code class=\"lang-php\">A double metaphone pecl module is available: http:\/\/pecl.php.net\/package\/doublemetaphone<\/code><\/pre>\n<p>Contributed By: Vipindas K.S<\/p>\n<pre><code class=\"lang-php\">Metaphone\n=======================\nThe metaphone() function can be used for spelling applications.This function returns the metaphone key of the string on success, or FALSE on failure.Its main use is when you are searching a genealogy database. check to see if a metaphone search is offered. It is also useful in making\/searching family tree.\nGiven below is a simple code that calculates and compares two strings to find whether its metaphone codes are equivalent.\nhtml code\n==========\n&lt;html&gt;\n&lt;body&gt;\n&lt;form action=\"test.php\" name=\"test\" method=\"get\"&gt;\nName1:&lt;input type=\"text\" name=\"name1\" \/&gt;&lt;br \/&gt;\nName2:&lt;input type=\"text\" name=\"name2\" \/&gt;&lt;br \/&gt;\n&lt;input type=\"submit\" name=\"submit\" value=\"compare\" \/&gt;\n&lt;\/form&gt;\n&lt;!--php code begins here --&gt;\n&lt;?php\nif(isset($_GET['submit']))\n{\n$str1 = $_GET['name1'];\n$str2 = $_GET['name2'];\n$meta_one=metaphone($str1);\n$meta_two=metaphone($str2);\necho \"metaphone code for \".$str1.\" is \". $meta_one;\necho \"&lt;br \/&gt;\";\necho \"metaphone code for \".$str2.\" is \". $meta_two.\"&lt;br&gt;\";\nif($meta_one==$meta_two)\n{\necho \"metaphone codes are matching\";\n}\nelse\n{\necho \"metaphone codes are not matching\";\n}\n}\n?&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\nMetaphone  algorithm was developed by Lawrence Philips.\nLawrence Philips' RULES follow:\n The 16 consonant sounds:\n                                             |--- ZERO represents \"th\"\n                                             |\n      B  X  S  K  J  T  F  H  L  M  N  P  R  0  W  Y\n Exceptions:\n   Beginning of word: \"ae-\", \"gn\", \"kn-\", \"pn-\", \"wr-\"  ----&gt; drop first letter\n                      \"Aebersold\", \"Gnagy\", \"Knuth\", \"Pniewski\", \"Wright\"\n   Beginning of word: \"x\"                                ----&gt; change to \"s\"\n                                      as in \"Deng Xiaopeng\"\n   Beginning of word: \"wh-\"                              ----&gt; change to \"w\"\n                                      as in \"Whalen\"\n Transformations:\n   B ----&gt; B      unless at the end of word after \"m\", as in \"dumb\", \"McComb\"\n   C ----&gt; X      (sh) if \"-cia-\" or \"-ch-\"\n           S      if \"-ci-\", \"-ce-\", or \"-cy-\"\n                  SILENT if \"-sci-\", \"-sce-\", or \"-scy-\"\n           K      otherwise, including in \"-sch-\"\n   D ----&gt; J      if in \"-dge-\", \"-dgy-\", or \"-dgi-\"\n           T      otherwise\n   F ----&gt; F\n   G ----&gt;        SILENT if in \"-gh-\" and not at end or before a vowel\n                            in \"-gn\" or \"-gned\"\n                            in \"-dge-\" etc., as in above rule\n           J      if before \"i\", or \"e\", or \"y\" if not double \"gg\"\n           K      otherwise\n   H ----&gt;        SILENT if after vowel and no vowel follows\n                         or after \"-ch-\", \"-sh-\", \"-ph-\", \"-th-\", \"-gh-\"\n           H      otherwise\n   J ----&gt; J\n   K ----&gt;        SILENT if after \"c\"\n           K      otherwise\n   L ----&gt; L\n   M ----&gt; M\n   N ----&gt; N\n   P ----&gt; F      if before \"h\"\n           P      otherwise\n   Q ----&gt; K\n   R ----&gt; R\n   S ----&gt; X      (sh) if before \"h\" or in \"-sio-\" or \"-sia-\"\n           S      otherwise\n   T ----&gt; X      (sh) if \"-tia-\" or \"-tio-\"\n           0      (th) if before \"h\"\n                  silent if in \"-tch-\"\n           T      otherwise\n   V ----&gt; F\n   W ----&gt;        SILENT if not followed by a vowel\n           W      if followed by a vowel\n   X ----&gt; KS\n   Y ----&gt;        SILENT if not followed by a vowel\n           Y      if followed by a vowel\n   Z ----&gt; S<\/code><\/pre>\n<h2 id=\"money_format\">PHP <code>money_format()<\/code> Function<\/h2>\n<h3>What does <code>money_format()<\/code> do?<\/h3>\n<p>The PHP <code><code>money_format()<\/code><\/code> function will give you a formatted version of <code class=\"parameter\">number<\/code>. This function wraps the C library function <code>strfmon()<\/code>, with the difference that this implementation converts only one number at a time.<\/p>\n<h3>PHP <code>money_format()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> money_format ( string $format , float $number ) : string<\/code><\/pre>\n<h3>PHP <code>money_format()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>format<\/code> \u2014 The format specification consists of the following sequence: <\/p>\n<\/li>\n<li>\n<p><code>=f<\/code> \u2014 The character = followed by a (single byte) character f to be used as the numeric fill character. The default fill character is space. <\/p>\n<\/li>\n<li>\n<p><code>^<\/code> \u2014 Disable the use of grouping characters (as defined by the current locale). <\/p>\n<\/li>\n<li>\n<p><code>+ or (<\/code> \u2014 Specify the formatting style for positive and negative numbers. If + is used, the locale&#8217;s equivalent for + and &#8211; will be used. If ( is used, negative amounts are enclosed in parenthesis. If no specification is given, the default is +. <\/p>\n<\/li>\n<li>\n<p><code>!<\/code> \u2014 Suppress the currency symbol from the output string. <\/p>\n<\/li>\n<li>\n<p><code>-<\/code> \u2014 If present, it will make all fields left-justified (padded to the right), as opposed to the default which is for the fields to be right-justified (padded to the left). <\/p>\n<\/li>\n<li>\n<p><code>w<\/code> \u2014 A decimal digit string specifying a minimum field width. Field will be right-justified unless the flag &#8211; is used. Default value is 0 (zero). <\/p>\n<\/li>\n<li>\n<p><code>#n<\/code> \u2014 The maximum number of digits (n) expected to the left of the decimal character (e.g. the decimal point). It is used usually to keep formatted output aligned in the same columns, using the fill character if the number of digits is less than n. If the number of actual digits is bigger than n, then this specification is ignored. <\/p>\n<\/li>\n<li>\n<p><code>.p<\/code> \u2014 A period followed by the number of digits (p) after the decimal character. If the value of p is 0 (zero), the decimal character and the digits to its right will be omitted. If no right precision is included, the default will dictated by the current local in use. The amount being formatted is rounded to the specified number of digits prior to formatting. <\/p>\n<\/li>\n<li>\n<p><code>i<\/code> \u2014 The number is formatted according to the locale&#8217;s international currency format (e.g. for the USA locale: USD 1,234.56). <\/p>\n<\/li>\n<li>\n<p><code>n<\/code> \u2014 The number is formatted according to the locale&#8217;s national currency format (e.g. for the de_DE locale: EU1.234,56). <\/p>\n<\/li>\n<li>\n<p><code>%<\/code> \u2014 Returns the % character. <\/p>\n<\/li>\n<li>\n<p><code>number<\/code> \u2014 The number to be formatted. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>money_format()<\/code> Return Value<\/h3>\n<p>The PHP <code>money_format()<\/code> function returns the formatted string. Characters before and after the formatting string will be returned unchanged. Non-numeric <code class=\"parameter\">number<\/code> causes returning <code>NULL<\/code> and emitting <code>E_WARNING<\/code>.<\/p>\n<h3>PHP <code>money_format()<\/code> Working Examples<\/h3>\n<h4>1. money_format() Example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$number = 1234.56;\n\/\/ let's print the international format for the en_US locale\nsetlocale(LC_MONETARY, 'en_US');\necho money_format('%i', $number) . \"\\n\";\n\/\/ USD 1,234.56\n\/\/ Italian national format with 2 decimals`\nsetlocale(LC_MONETARY, 'it_IT');\necho money_format('%.2n', $number) . \"\\n\";\n\/\/ Eu 1.234,56\n\/\/ Using a negative number\n$number = -1234.5672;\n\/\/ US national format, using () for negative numbers\n\/\/ and 10 digits for left precision\nsetlocale(LC_MONETARY, 'en_US');\necho money_format('%(#10n', $number) . \"\\n\";\n\/\/ ($        1,234.57)\n\/\/ Similar format as above, adding the use of 2 digits of right\n\/\/ precision and '*' as a fill character\necho money_format('%=*(#10.2n', $number) . \"\\n\";\n\/\/ ($********1,234.57)\n\/\/ Let's justify to the left, with 14 positions of width, 8 digits of\n\/\/ left precision, 2 of right precision, without the grouping character\n\/\/ and using the international format for the de_DE locale.\nsetlocale(LC_MONETARY, 'de_DE');\necho money_format('%=*^-14#8.2i', 1234.56) . \"\\n\";\n\/\/ Eu 1234,56****\n\/\/ Let's add some blurb before and after the conversion specification\nsetlocale(LC_MONETARY, 'en_GB');\n$fmt = 'The final value is %i (after a 10%% discount)';\necho money_format($fmt, 1234.56) . \"\\n\";\n\/\/ The final value is  GBP 1,234.56 (after a 10% discount)\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>money_format()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The function <code>money_format()<\/code> is only defined if the system has strfmon capabilities. For example, Windows does not, so <code>money_format()<\/code> is undefined in Windows. <\/p>\n<\/li>\n<li>\n<p> The <code>LC_MONETARY<\/code> category of the locale settings, affects the behavior of this function. Use <code>setlocale()<\/code> to set to the appropriate default locale before using this function. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: tim<\/p>\n<pre><code class=\"lang-php\">For most of us in the US, we don't want to see a \"USD\" for our currency symbol, so '%i' doesn't cut it.  Here's what I used that worked to get what most  people expect to see for a number format.\n$number = 123.4\nsetlocale(LC_MONETARY, 'en_US.UTF-8');\nmoney_format('%.2n', $number);\noutput:\n$123.40\nThat gives me a dollar sign at the beginning, and 2 digits at the end.<\/code><\/pre>\n<p>Contributed By: Rafael M. Salvioni<\/p>\n<pre><code class=\"lang-php\">This is a some function posted before, however various bugs were corrected. \n \nThank you to Stuart Roe by reporting the bug on printing signals. \n \n&lt;?php \n\/* \nThat it is an implementation of the function money_format for the \nplatforms that do not it bear.  \n \nThe function accepts to same string of format accepts for the \noriginal function of the PHP.  \n \n(Sorry. my writing in English is very bad)  \n \nThe function is tested using PHP 5.1.4 in Windows XP \nand Apache WebServer. \n*\/ \nfunction money_format($format, $number) \n{ \n    $regex  = '\/%((?:[\\^!\\-]|\\+|\\(|\\=.)*)([0-9]+)?'. \n              '(?:#([0-9]+))?(?:\\.([0-9]+))?([in%])\/'; \n    if (setlocale(LC_MONETARY, 0) == 'C') { \n        setlocale(LC_MONETARY, ''); \n    } \n    $locale = localeconv(); \n    preg_match_all($regex, $format, $matches, PREG_SET_ORDER); \n    foreach ($matches as $fmatch) { \n        $value = floatval($number); \n        $flags = array( \n            'fillchar'  =&gt; preg_match('\/\\=(.)\/', $fmatch[1], $match) ? \n                           $match[1] : ' ', \n            'nogroup'   =&gt; preg_match('\/\\^\/', $fmatch[1]) &gt; 0, \n            'usesignal' =&gt; preg_match('\/\\+|\\(\/', $fmatch[1], $match) ? \n                           $match[0] : '+', \n            'nosimbol'  =&gt; preg_match('\/\\!\/', $fmatch[1]) &gt; 0, \n            'isleft'    =&gt; preg_match('\/\\-\/', $fmatch[1]) &gt; 0 \n        ); \n        $width      = trim($fmatch[2]) ? (int)$fmatch[2] : 0; \n        $left       = trim($fmatch[3]) ? (int)$fmatch[3] : 0; \n        $right      = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; \n        $conversion = $fmatch[5]; \n \n        $positive = true; \n        if ($value &lt; 0) { \n            $positive = false; \n            $value  *= -1; \n        } \n        $letter = $positive ? 'p' : 'n'; \n \n        $prefix = $suffix = $cprefix = $csuffix = $signal = ''; \n \n        $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign']; \n        switch (true) { \n            case $locale[\"{$letter}_sign_posn\"] == 1 &amp;&amp; $flags['usesignal'] == '+': \n                $prefix = $signal; \n                break; \n            case $locale[\"{$letter}_sign_posn\"] == 2 &amp;&amp; $flags['usesignal'] == '+': \n                $suffix = $signal; \n                break; \n            case $locale[\"{$letter}_sign_posn\"] == 3 &amp;&amp; $flags['usesignal'] == '+': \n                $cprefix = $signal; \n                break; \n            case $locale[\"{$letter}_sign_posn\"] == 4 &amp;&amp; $flags['usesignal'] == '+': \n                $csuffix = $signal; \n                break; \n            case $flags['usesignal'] == '(': \n            case $locale[\"{$letter}_sign_posn\"] == 0: \n                $prefix = '('; \n                $suffix = ')'; \n                break; \n        } \n        if (!$flags['nosimbol']) { \n            $currency = $cprefix . \n                        ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . \n                        $csuffix; \n        } else { \n            $currency = ''; \n        } \n        $space  = $locale[\"{$letter}_sep_by_space\"] ? ' ' : ''; \n \n        $value = number_format($value, $right, $locale['mon_decimal_point'], \n                 $flags['nogroup'] ? '' : $locale['mon_thousands_sep']); \n        $value = @explode($locale['mon_decimal_point'], $value); \n \n        $n = strlen($prefix) + strlen($currency) + strlen($value[0]); \n        if ($left &gt; 0 &amp;&amp; $left &gt; $n) { \n            $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0]; \n        } \n        $value = implode($locale['mon_decimal_point'], $value); \n        if ($locale[\"{$letter}_cs_precedes\"]) { \n            $value = $prefix . $currency . $space . $value . $suffix; \n        } else { \n            $value = $prefix . $value . $space . $currency . $suffix; \n        } \n        if ($width &gt; 0) { \n            $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? \n                     STR_PAD_RIGHT : STR_PAD_LEFT); \n        } \n \n        $format = str_replace($fmatch[0], $value, $format); \n    } \n    return $format; \n} \n \n?&gt;<\/code><\/pre>\n<p>Contributed By: todoventas<\/p>\n<pre><code class=\"lang-php\">In Rafael M. Salvioni function localeconv(); returns an invalid array in my Windows XP SP3 running PHP 5.4.13 so to prevent the Warning Message: implode(): Invalid arguments passed i just add the $locale manually. For other languages just fill the array with the correct settings.\n&lt;?\n       $locale = array(\n        'decimal_point'        =&gt; '.',\n        'thousands_sep'        =&gt; '',\n        'int_curr_symbol'    =&gt; 'EUR',\n        'currency_symbol'    =&gt; '\u20ac',\n        'mon_decimal_point'    =&gt; ',',\n        'mon_thousands_sep'    =&gt; '.',\n        'positive_sign'        =&gt; '',\n        'negative_sign'     =&gt; '-',\n        'int_frac_digits'    =&gt; 2,\n        'frac_digits'        =&gt; 2,\n        'p_cs_precedes'        =&gt; 0,\n        'p_sep_by_space'    =&gt; 1,\n        'p_sign_posn'        =&gt; 1,\n        'n_sign_posn'        =&gt; 1,\n        'grouping'            =&gt; array(),\n        'mon_grouping'        =&gt; array(0 =&gt; 3, 1 =&gt; 3)\n        \n    );\n?&gt;<\/code><\/pre>\n<p>Contributed By: jeremy<\/p>\n<pre><code class=\"lang-php\">If money_format doesn't seem to be working properly, make sure you are defining a valid locale.  For example, on Debian, 'en_US' is not a valid locale - you need 'en_US.UTF-8' or 'en_US.ISO-8559-1'.\nThis was frustrating me for a while.  Debian has a list of valid locales at \/usr\/share\/i18n\/SUPPORTED; find yours there if it's not working properly.<\/code><\/pre>\n<h2 id=\"nl2br\">PHP <code>nl2br()<\/code> Function<\/h2>\n<h3>What does <code>nl2br()<\/code> do?<\/h3>\n<p>The PHP <code><code>nl2br()<\/code><\/code> function will inserts HTML line breaks before all newlines in a string.<\/p>\n<h3>PHP <code>nl2br()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> nl2br ( string $string [, bool $is_xhtml = TRUE ] ) : string<\/code><\/pre>\n<h3>PHP <code>nl2br()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>is_xhtml<\/code> \u2014 Whether to use XHTML compatible line breaks or not. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>nl2br()<\/code> Return Value<\/h3>\n<p>The PHP <code>nl2br()<\/code> function returns the altered string.<\/p>\n<h3>PHP <code>nl2br()<\/code> Working Examples<\/h3>\n<h4>1. Using nl2br()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho nl2br(\"foo isn't\\n bar\");\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">foo isn't&lt;br \/&gt;\n bar<\/code><\/pre>\n<h4>2. Generating valid HTML markup using the is_xhtml parameter<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho nl2br(\"Welcome\\r\\nThis is my HTML document\", false);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Welcome&lt;br&gt;\nThis is my HTML document<\/code><\/pre>\n<h4>3. Various newline separators<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$string = \"This\\r\\nis\\n\\ra\\nstring\\r\";\necho nl2br($string);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">This&lt;br \/&gt;\nis&lt;br \/&gt;\na&lt;br \/&gt;\nstring&lt;br \/&gt;<\/code><\/pre>\n<h3>Changelog for PHP nl2br()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> Added the optional <code class=\"parameter\">is_xhtml<\/code> parameter. Before this version &#8216;&lt;br \/&gt;&#8217; was always inserted. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: CGameProgrammer<\/p>\n<pre><code class=\"lang-php\">It's important to remember that this function does NOT replace newlines with &lt;br&gt; tags. Rather, it inserts a &lt;br&gt; tag before each newline, but it still preserves the newlines themselves! This caused problems for me regarding a function I was writing -- I forgot the newlines were still being preserved. \n \nIf you don't want newlines, do: \n \n&lt;?php \n$Result = str_replace( \"\\n\", '&lt;br \/&gt;', $Text ); \n?&gt;<\/code><\/pre>\n<p>Contributed By: ngkongs<\/p>\n<pre><code class=\"lang-php\">To replace all linebreaks to &lt;br \/&gt; \nthe best solution (IMO) is: \n \n&lt;?php \nfunction nl2br2($string) { \n$string = str_replace(array(\"\\r\\n\", \"\\r\", \"\\n\"), \"&lt;br \/&gt;\", $string); \nreturn $string; \n} \n?&gt; \n \nbecause each OS have different ASCII chars for linebreak: \nwindows = \\r\\n \nunix = \\n \nmac = \\r \n \nworks perfect for me<\/code><\/pre>\n<p>Contributed By: N\/A<\/p>\n<pre><code class=\"lang-php\">Here's a more simple one:\n&lt;?php\n\/**\n * Convert BR tags to nl\n *\n * @param string The string to convert\n * @return string The converted string\n *\/\nfunction br2nl($string)\n{\n    return preg_replace('\/\\&lt;br(\\s*)?\\\/?\\&gt;\/i', \"\\n\", $string);\n}\n?&gt;\nEnjoy<\/code><\/pre>\n<p>Contributed By: fquffio<\/p>\n<pre><code class=\"lang-php\">Starting from PHP 4.3.10 and PHP 5.0.2, this should be the most correct way to replace &lt;br \/&gt; and &lt;br&gt; tags with newlines and carriage returns.\n&lt;?php\n\/**\n * Convert BR tags to newlines and carriage returns.\n *\n * @param string The string to convert\n * @return string The converted string\n *\/\nfunction br2nl ( $string )\n{\n    return preg_replace('\/\\&lt;br(\\s*)?\\\/?\\&gt;\/i', PHP_EOL, $string);\n}\n?&gt;\n(Please note this is a minor edit of this function: http:\/\/php.net\/nl2br#86678 )\nYou might also want to be \"platform specific\", and therefore this function might be of some help:\n&lt;?php\n\/**\n * Convert BR tags to newlines and carriage returns.\n *\n * @param string The string to convert\n * @param string The string to use as line separator\n * @return string The converted string\n *\/\nfunction br2nl ( $string, $separator = PHP_EOL )\n{\n    $separator = in_array($separator, array(\"\\n\", \"\\r\", \"\\r\\n\", \"\\n\\r\", chr(30), chr(155), PHP_EOL)) ? $separator : PHP_EOL;  \/\/ Checks if provided $separator is valid.\n    return preg_replace('\/\\&lt;br(\\s*)?\\\/?\\&gt;\/i', $separator, $string);\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"nl_langinfo\">PHP <code>nl_langinfo()<\/code> Function<\/h2>\n<h3>What does <code>nl_langinfo()<\/code> do?<\/h3>\n<p>The PHP <code><code>nl_langinfo()<\/code><\/code> function will give you all of the elements, <code>nl_langinfo()<\/code> allows you to select any specific element.<\/p>\n<h3>PHP <code>nl_langinfo()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> nl_langinfo ( int $item ) : string<\/code><\/pre>\n<h3>PHP <code>nl_langinfo()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>item<\/code> \u2014 item may be an integer value of the element or the constant name of the element. The following is a list of constant names for item that may be used and their description. Some of these constants may not be defined or hold no value for certain locales. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>nl_langinfo()<\/code> Return Value<\/h3>\n<p>The PHP <code>nl_langinfo()<\/code> function returns the element as a string, or <code>FALSE<\/code> if <code class=\"parameter\">item<\/code> is not valid.<\/p>\n<h2 id=\"number_format\">PHP <code>number_format()<\/code> Function<\/h2>\n<h3>What does <code>number_format()<\/code> do?<\/h3>\n<p>The PHP <code><code>number_format()<\/code><\/code> function will this function accepts either one, two, or four parameters (not three):<\/p>\n<h3>PHP <code>number_format()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> number_format ( float $number [, int $decimals = 0 ] ) : string<\/code><\/pre>\n<pre><code class=\"lang-php\"> number_format ( float $number , int $decimals = 0 , string $dec_point = \".\" , string $thousands_sep = \",\" ) : string<\/code><\/pre>\n<h3>PHP <code>number_format()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>number<\/code> \u2014 The number being formatted. <\/p>\n<\/li>\n<li>\n<p><code>decimals<\/code> \u2014 Sets the number of decimal points. <\/p>\n<\/li>\n<li>\n<p><code>dec_point<\/code> \u2014 Sets the separator for the decimal point. <\/p>\n<\/li>\n<li>\n<p><code>thousands_sep<\/code> \u2014 Sets the thousands separator. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>number_format()<\/code> Return Value<\/h3>\n<p>The PHP <code>number_format()<\/code> function returns a formatted version of <code class=\"parameter\">number<\/code>.<\/p>\n<h3>PHP <code>number_format()<\/code> Working Examples<\/h3>\n<h4>1. number_format() Example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$number = 1234.56;\n\/\/ english notation (default)\n$english_format_number = number_format($number);\n\/\/ 1,235\n\/\/ French notation\n$nombre_format_francais = number_format($number, 2, ',', ' ');\n\/\/ 1 234,56\n$number = 1234.5678;\n\/\/ english notation without thousands separator\n$english_format_number = number_format($number, 2, '.', '');\n\/\/ 1234.57\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP number_format()<\/code> Function<\/h3>\n<p><strong>7.2.0 \u2014 <\/strong> <code>number_format()<\/code> was changed to not being able to return -0, previously -0 could be returned for cases like where <code class=\"parameter\">number<\/code> would be -0.01. <\/p>\n<p><strong>5.4.0 \u2014 <\/strong> This function now supports multiple bytes in <code class=\"parameter\">dec_point<\/code> and <code class=\"parameter\">thousands_sep<\/code>. Only the first byte of each separator was used in older versions. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: thomas<\/p>\n<pre><code class=\"lang-php\">It's not explicitly documented; number_format also rounds:\n&lt;?php\n$numbers = array(0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009);\nforeach ($numbers as $number)\n    print $number.\"-&gt;\".number_format($number, 2, '.', ',').\"&lt;br&gt;\";\n?&gt;\n0.001-&gt;0.00\n0.002-&gt;0.00\n0.003-&gt;0.00\n0.004-&gt;0.00\n0.005-&gt;0.01\n0.006-&gt;0.01\n0.007-&gt;0.01\n0.008-&gt;0.01\n0.009-&gt;0.01<\/code><\/pre>\n<p>Contributed By: james<\/p>\n<pre><code class=\"lang-php\">Outputs a human readable number.\n&lt;?php\n    #    Output easy-to-read numbers\n    #    by james at bandit.co.nz\n    function bd_nice_number($n) {\n        \/\/ first strip any formatting;\n        $n = (0+str_replace(\",\",\"\",$n));\n        \n        \/\/ is this a number?\n        if(!is_numeric($n)) return false;\n        \n        \/\/ now filter it;\n        if($n&gt;1000000000000) return round(($n\/1000000000000),1).' trillion';\n        else if($n&gt;1000000000) return round(($n\/1000000000),1).' billion';\n        else if($n&gt;1000000) return round(($n\/1000000),1).' million';\n        else if($n&gt;1000) return round(($n\/1000),1).' thousand';\n        \n        return number_format($n);\n    }\n?&gt;\nOutputs:\n247,704,360 -&gt; 247.7 million\n866,965,260,000 -&gt; 867 billion<\/code><\/pre>\n<p>Contributed By: stm555<\/p>\n<pre><code class=\"lang-php\">I ran across an issue where I wanted to keep the entered precision of a real value, without arbitrarily rounding off what the user had submitted.\nI figured it out with a quick explode on the number before formatting. I could then format either side of the decimal.\n&lt;?php\n      function number_format_unlimited_precision($number,$decimal = '.')\n      {\n           $broken_number = explode($decimal,$number);\n           return number_format($broken_number[0]).$decimal.$broken_number[1];\n      }\n?&gt;<\/code><\/pre>\n<p>Contributed By: MarcM<\/p>\n<pre><code class=\"lang-php\">For Zero fill - just use the sprintf() function\n$pr_id = 1;\n$pr_id = sprintf(\"%03d\", $pr_id);\necho $pr_id;\n\/\/outputs 001\n-----------------\n$pr_id = 10;\n$pr_id = sprintf(\"%03d\", $pr_id);\necho $pr_id;\n\/\/outputs 010\n-----------------\nYou can change %03d to %04d, etc.<\/code><\/pre>\n<h2 id=\"ord\">PHP <code>ord()<\/code> Function<\/h2>\n<h3>What does <code>ord()<\/code> do?<\/h3>\n<p>The PHP <code><code>ord()<\/code><\/code> function will convert the first byte of a string to a value between 0 and 255.<\/p>\n<h3>PHP <code>ord()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> ord ( string $string ) : int<\/code><\/pre>\n<h3>PHP <code>ord()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 A character. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>ord()<\/code> Return Value<\/h3>\n<p>The PHP <code>ord()<\/code> function returns an integer between 0 and 255.<\/p>\n<h3>PHP <code>ord()<\/code> Working Examples<\/h3>\n<h4>1. ord() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"\\n\";\nif (ord($str) == 10) {\n    echo \"The first character of \\$str is a line feed.\\n\";\n}\n?&gt;<\/code><\/pre>\n<h4>2. Examining the individual bytes of a UTF-8 string<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\ndeclare(encoding='UTF-8');\n$str = \"\ud83d\udc18\";\nfor ( $pos=0; $pos &lt; strlen($str); $pos ++ ) {\n $byte = substr($str, $pos);\n echo 'Byte ' . $pos . ' of $str has value ' . ord($byte) . PHP_EOL;\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\"><br>\nByte 0 of $str has value 240<br>\nByte 1 of $str has value 159<br>\nByte 2 of $str has value 144<br>\nByte 3 of $str has value 152<br><\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: arglanir+phpnet<\/p>\n<pre><code class=\"lang-php\">As ord() doesn't work with utf-8, and if you do not have access to mb_* functions, the following function will work well:\n&lt;?php\nfunction ordutf8($string, &amp;$offset) {\n    $code = ord(substr($string, $offset,1)); \n    if ($code &gt;= 128) {        \/\/otherwise 0xxxxxxx\n        if ($code &lt; 224) $bytesnumber = 2;                \/\/110xxxxx\n        else if ($code &lt; 240) $bytesnumber = 3;        \/\/1110xxxx\n        else if ($code &lt; 248) $bytesnumber = 4;    \/\/11110xxx\n        $codetemp = $code - 192 - ($bytesnumber &gt; 2 ? 32 : 0) - ($bytesnumber &gt; 3 ? 16 : 0);\n        for ($i = 2; $i &lt;= $bytesnumber; $i++) {\n            $offset ++;\n            $code2 = ord(substr($string, $offset, 1)) - 128;        \/\/10xxxxxx\n            $codetemp = $codetemp*64 + $code2;\n        }\n        $code = $codetemp;\n    }\n    $offset += 1;\n    if ($offset &gt;= strlen($string)) $offset = -1;\n    return $code;\n}\n?&gt;\n$offset is a reference, as it is not easy to split a utf-8 char-by-char. Useful to iterate on a string:\n&lt;?php\n$text = \"abc\u00e0\u00ea\u00df\u20acabc\";\n$offset = 0;\nwhile ($offset &gt;= 0) {\n    echo $offset.\": \".ordutf8($text, $offset).\"\\n\";\n}\n\/* returns:\n0: 97\n1: 98\n2: 99\n3: 224\n5: 234\n7: 223\n9: 8364\n12: 97\n13: 98\n14: 99\n*\/\n?&gt;\nFeel free to adapt my code to fit your needs.<\/code><\/pre>\n<p>Contributed By: rowan dot collins<\/p>\n<pre><code class=\"lang-php\">Regarding character sets, and whether or not this is \"ASCII\". Firstly, there is no such thing as \"8-bit ASCII\", so if it were ASCII it would only ever return integers up to 127. 8-bit ASCII-compatible encodings include the ISO 8859 family of encodings, which map various common characters to the values from 128 to 255. UTF-8 is also designed so that characters representable in 7-bit ASCII are coded the same; byte values higher than 127 in a UTF-8 string represent the beginning of a multi-byte character.\nIn fact, like most of PHP's string functions, this function isn't doing anything to do with character encoding at all - it is just interpreting a binary byte from a string as an unsigned integer. That is, ord(chr(200)) will always return 200, but what character chr(200) *means* will vary depending on what character encoding it is *interpreted* as part of (e.g. during display).\nA technically correct description would be \"Returns an integer representation of the first byte of a string, from 0 to 255. For single-byte encodings such as (7-bit) ASCII and the ISO 8859 family, this will correspond to the first character, and will be the position of that character in the encoding's mapping table. For multi-byte encodings, such as UTF-8 or UTF-16, the byte may not represent a complete character.\"\nThe link to asciitable.com should also be replaced by one which explains what character encoding it is displaying, as \"Extended ASCII\" is an ambiguous and misleading name.<\/code><\/pre>\n<h2 id=\"parse_str\">PHP <code>parse_str()<\/code> Function<\/h2>\n<h3>What does <code>parse_str()<\/code> do?<\/h3>\n<p>The PHP <code><code>parse_str()<\/code><\/code> function will parses <code class=\"parameter\">encoded_string<\/code> as if it were the query string passed via a URL and sets variables in the current scope (or in the array if <code class=\"parameter\">result<\/code> is provided).<\/p>\n<h3>PHP <code>parse_str()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> parse_str ( string $encoded_string [, array &$result ] ) : void<\/code><\/pre>\n<h3>PHP <code>parse_str()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>encoded_string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>result<\/code> \u2014 If the second parameter result is present, variables are stored in this variable as array elements instead. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>parse_str()<\/code> Return Value<\/h3>\n<p>The PHP <code>parse_str()<\/code> function returns d.<\/p>\n<h3>PHP <code>parse_str()<\/code> Working Examples<\/h3>\n<h4>1. Using parse_str()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"first=value&amp;arr[]=foo+bar&amp;arr[]=baz\";\n\/\/ Recommended\nparse_str($str, $output);\necho $output['first'];  \/\/ value\necho $output['arr'][0]; \/\/ foo bar\necho $output['arr'][1]; \/\/ baz\n\/\/ DISCOURAGED\nparse_str($str);\necho $first;  \/\/ value\necho $arr[0]; \/\/ foo bar\necho $arr[1]; \/\/ baz\n?&gt;<\/code><\/pre>\n<h4>2. parse_str() name mangling<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nparse_str(\"My Value=Something\");\necho $My_Value; \/\/ Something\nparse_str(\"My Value=Something\", $output);\necho $output['My_Value']; \/\/ Something\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP parse_str()<\/code> Function<\/h3>\n<p><strong>7.2.0 \u2014 <\/strong> Usage of <code>parse_str()<\/code> without a second parameter now emits an <code>E_DEPRECATED<\/code> notice. <\/p>\n<h3>Important Points about PHP <code>parse_str()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Using this function without the <code class=\"parameter\">result<\/code> parameter is highly <strong>DISCOURAGED<\/strong> and <strong>DEPRECATED<\/strong> as of PHP 7.2. <\/p>\n<\/li>\n<li>\n<p> Dynamically setting variables in function&#8217;s scope suffers from exactly same problems as register_globals. <\/p>\n<\/li>\n<li>\n<p> Read section on security of Using Register Globals explaining why it is dangerous. <\/p>\n<\/li>\n<li>\n<p> All variables created (or values returned into array if second parameter is set) are already <code>urldecode()<\/code>d. <\/p>\n<\/li>\n<li>\n<p> To get the current <strong>QUERY_STRING<\/strong>, you may use the variable $_SERVER[&#8216;QUERY_STRING&#8217;]. Also, you may want to read the section on variables from external sources. <\/p>\n<\/li>\n<li>\n<p> The magic_quotes_gpc setting affects the output of this function, as <code>parse_str()<\/code> uses the same mechanism that PHP uses to populate the $_GET, $_POST, etc. variables. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Evan K<\/p>\n<pre><code class=\"lang-php\">It bears mentioning that the parse_str builtin does NOT process a query string in the CGI standard way, when it comes to duplicate fields.  If multiple fields of the same name exist in a query string, every other web processing language would read them into an array, but PHP silently overwrites them:\n&lt;?php\n# silently fails to handle multiple values\nparse_str('foo=1&amp;foo=2&amp;foo=3');\n# the above produces:\n$foo = array('foo' =&gt; '3');\n?&gt;\nInstead, PHP uses a non-standards compliant practice of including brackets in fieldnames to achieve the same effect.\n&lt;?php\n# bizarre php-specific behavior\nparse_str('foo[]=1&amp;foo[]=2&amp;foo[]=3');\n# the above produces:\n$foo = array('foo' =&gt; array('1', '2', '3') );\n?&gt;\nThis can be confusing for anyone who's used to the CGI standard, so keep it in mind.  As an alternative, I use a \"proper\" querystring parser function:\n&lt;?php\nfunction proper_parse_str($str) {\n  # result array\n  $arr = array();\n  # split on outer delimiter\n  $pairs = explode('&amp;', $str);\n  # loop through each pair\n  foreach ($pairs as $i) {\n    # split into name and value\n    list($name,$value) = explode('=', $i, 2);\n    \n    # if name already exists\n    if( isset($arr[$name]) ) {\n      # stick multiple values into an array\n      if( is_array($arr[$name]) ) {\n        $arr[$name][] = $value;\n      }\n      else {\n        $arr[$name] = array($arr[$name], $value);\n      }\n    }\n    # otherwise, simply stick it in a scalar\n    else {\n      $arr[$name] = $value;\n    }\n  }\n  # return result array\n  return $arr;\n}\n$query = proper_parse_str($_SERVER['QUERY_STRING']);\n?&gt;<\/code><\/pre>\n<p>Contributed By: shagshag<\/p>\n<pre><code class=\"lang-php\">That's not says in the description but max_input_vars directive affects this function. If there are more input variables on the string than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.<\/code><\/pre>\n<p>Contributed By: Olivier Mengu\u00e9<\/p>\n<pre><code class=\"lang-php\">Vladimir: the function is OK in how it deals with &amp;amp;.\n&amp;amp; must only be used when outputing URLs in HTML\/XML data.\nYou should ask yourself why you have &amp;amp; in your URL when you give it to parse_str.<\/code><\/pre>\n<h2 id=\"print\">PHP <code>print()<\/code> Function<\/h2>\n<h3>What does <code>print()<\/code> do?<\/h3>\n<p>The PHP <code><code>print()<\/code><\/code> function will outputs <code class=\"parameter\">arg<\/code>.<\/p>\n<h3>PHP <code>print()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> print ( string $arg ) : int<\/code><\/pre>\n<h3>PHP <code>print()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The input data. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>print()<\/code> Return Value<\/h3>\n<p>The PHP <code>print()<\/code> function returns <strong>1<\/strong>, always.<\/p>\n<h3>PHP <code>print()<\/code> Working Examples<\/h3>\n<h4>1. print examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nprint(\"Hello World\");\nprint \"print() also works without parentheses.\";\nprint \"This spans\nmultiple lines. The newlines will be\noutput as well\";\nprint \"This spans\\nmultiple lines. The newlines will be\\noutput as well.\";\nprint \"escaping characters is done \\\"Like this\\\".\";\n\/\/ You can use variables inside a print statement\n$foo = \"foobar\";\n$bar = \"barbaz\";\nprint \"foo is $foo\"; \/\/ foo is foobar\n\/\/ You can also use arrays\n$bar = array(\"value\" =&gt; \"foo\");\nprint \"this is {$bar['value']} !\"; \/\/ this is foo !\n\/\/ Using single quotes will print the variable name, not the value\nprint 'foo is $foo'; \/\/ foo is $foo\n\/\/ If you are not using any other characters, you can just print variables\nprint $foo;          \/\/ foobar\nprint &lt;&lt;&lt;END\nThis uses the \"here document\" syntax to output\nmultiple lines with $variable interpolation. Note\nthat the here document terminator must appear on a\nline with just a semicolon no extra whitespace!\nEND;\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: user<\/p>\n<pre><code class=\"lang-php\">Be careful when using print. Since print is a language construct and not a function, the parentheses around the argument is not required.\nIn fact, using parentheses can cause confusion with the syntax of a function and SHOULD be omited.\nMost would expect the following behavior:\n&lt;?php\n    if (print(\"foo\") &amp;&amp; print(\"bar\")) {\n        \/\/ \"foo\" and \"bar\" had been printed\n    }\n?&gt;\nBut since the parenthesis around the argument are not required, they are interpretet as part of the argument.\nThis means that the argument of the first print is\n    (\"foo\") &amp;&amp; print(\"bar\")\nand the argument of the second print is just\n    (\"bar\")\nFor the expected behavior of the first example, you need to write: \n&lt;?php\n    if ((print \"foo\") &amp;&amp; (print \"bar\")) {\n        \/\/ \"foo\" and \"bar\" had been printed\n    }\n?&gt;<\/code><\/pre>\n<p>Contributed By: danielxmorris @ gmail dotcom<\/p>\n<pre><code class=\"lang-php\">I wrote a println function that determines whether a \\n or a &lt;br \/&gt; should be appended to the line depending on whether it's being executed in a shell or a browser window.  People have probably thought of this before but I thought I'd post it anyway - it may help a couple of people.\n&lt;?php\nfunction println ($string_message) {\n    $_SERVER['SERVER_PROTOCOL'] ? print \"$string_message&lt;br \/&gt;\" : print \"$string_message\\n\";\n}\n?&gt;\nExamples:\nRunning in a browser:\n&lt;?php println (\"Hello, world!\"); ?&gt;\nOutput: Hello, world!&lt;br \/&gt;\nRunning in a shell:\n&lt;?php println (\"Hello, world!\"); ?&gt;\nOutput: Hello, world!\\n<\/code><\/pre>\n<h2 id=\"printf\">PHP <code>printf()<\/code> Function<\/h2>\n<h3>What does <code>printf()<\/code> do?<\/h3>\n<p>The PHP <code><code>printf()<\/code><\/code> function will produces output according to <code class=\"parameter\">format<\/code>.<\/p>\n<h3>PHP <code>printf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> printf ( string $format [, mixed $... ] ) : int<\/code><\/pre>\n<h3>PHP <code>printf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>printf()<\/code> Return Value<\/h3>\n<p>The PHP <code>printf()<\/code> function returns the length of the outputted string.<\/p>\n<h3>PHP <code>printf()<\/code> Working Examples<\/h3>\n<h4>1. printf(): various examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$n =  43951789;\n$u = -43951789;\n$c = 65; \/\/ ASCII 65 is 'A'\n\/\/ notice the double %%, this prints a literal '%' character\nprintf(\"%%b = '%b'\\n\", $n); \/\/ binary representation\nprintf(\"%%c = '%c'\\n\", $c); \/\/ print the ascii character, same as chr() function\nprintf(\"%%d = '%d'\\n\", $n); \/\/ standard integer representation\nprintf(\"%%e = '%e'\\n\", $n); \/\/ scientific notation\nprintf(\"%%u = '%u'\\n\", $n); \/\/ unsigned integer representation of a positive integer\nprintf(\"%%u = '%u'\\n\", $u); \/\/ unsigned integer representation of a negative integer\nprintf(\"%%f = '%f'\\n\", $n); \/\/ floating point representation\nprintf(\"%%o = '%o'\\n\", $n); \/\/ octal representation\nprintf(\"%%s = '%s'\\n\", $n); \/\/ string representation\nprintf(\"%%x = '%x'\\n\", $n); \/\/ hexadecimal representation (lower-case)\nprintf(\"%%X = '%X'\\n\", $n); \/\/ hexadecimal representation (upper-case)\nprintf(\"%%+d = '%+d'\\n\", $n); \/\/ sign specifier on a positive integer\nprintf(\"%%+d = '%+d'\\n\", $u); \/\/ sign specifier on a negative integer\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">%b = '10100111101010011010101101'\n%c = 'A'\n%d = '43951789'\n%e = '4.39518e+7'\n%u = '43951789'\n%u = '4251015507'\n%f = '43951789.000000'\n%o = '247523255'\n%s = '43951789'\n%x = '29ea6ad'\n%X = '29EA6AD'\n%+d = '+43951789'\n%+d = '-43951789'<\/code><\/pre>\n<h4>2. printf(): string specifiers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$s = 'monkey';\n$t = 'many monkeys';\nprintf(\"[%s]\\n\",      $s); \/\/ standard string output\nprintf(\"[%10s]\\n\",    $s); \/\/ right-justification with spaces\nprintf(\"[%-10s]\\n\",   $s); \/\/ left-justification with spaces\nprintf(\"[%010s]\\n\",   $s); \/\/ zero-padding works on strings too\nprintf(\"[%'#10s]\\n\",  $s); \/\/ use the custom padding character '#'\nprintf(\"[%10.9s]\\n\", $t); \/\/ right-justification but with a cutoff of 8 characters\nprintf(\"[%-10.9s]\\n\", $t); \/\/ left-justification but with a cutoff of 8 characters\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\"> \n[monkey]\n[ monkey]\n[monkey ]\n[0000monkey]\n[####monkey]\n[ many monk]\n[many monk ]<\/code><\/pre>\n<h3>Important Points about PHP <code>printf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"quoted_printable_decode\">PHP <code>quoted_printable_decode()<\/code> Function<\/h2>\n<h3>What does <code>quoted_printable_decode()<\/code> do?<\/h3>\n<p>The PHP <code><code>quoted_printable_decode()<\/code><\/code> function will convert a quoted-printable string to an 8 bit string.<\/p>\n<h3>PHP <code>quoted_printable_decode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> quoted_printable_decode ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>quoted_printable_decode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>quoted_printable_decode()<\/code> Return Value<\/h3>\n<p>The PHP <code>quoted_printable_decode()<\/code> function returns the 8-bit binary string.<\/p>\n<h2 id=\"quoted_printable_encode\">PHP <code>quoted_printable_encode()<\/code> Function<\/h2>\n<h3>What does <code>quoted_printable_encode()<\/code> do?<\/h3>\n<p>The PHP <code><code>quoted_printable_encode()<\/code><\/code> function will convert a 8 bit string to a quoted-printable string.<\/p>\n<h3>PHP <code>quoted_printable_encode()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> quoted_printable_encode ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>quoted_printable_encode()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>quoted_printable_encode()<\/code> Return Value<\/h3>\n<p>The PHP <code>quoted_printable_encode()<\/code> function returns the encoded string.<\/p>\n<h2 id=\"quotemeta\">PHP <code>quotemeta()<\/code> Function<\/h2>\n<h3>What does <code>quotemeta()<\/code> do?<\/h3>\n<p>The PHP <code><code>quotemeta()<\/code><\/code> function will give you a version of str with a backslash character (<strong>\\<\/strong>) before every character that is among these:<\/p>\n<h3>PHP <code>quotemeta()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> quotemeta ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>quotemeta()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>quotemeta()<\/code> Return Value<\/h3>\n<p>The PHP <code>quotemeta()<\/code> function returns the string with meta characters quoted, or <code>FALSE<\/code> if an empty string is given as <code class=\"parameter\">str<\/code>.<\/p>\n<h2 id=\"rtrim\">PHP <code>rtrim()<\/code> Function<\/h2>\n<h3>What does <code>rtrim()<\/code> do?<\/h3>\n<p>The PHP <code><code>rtrim()<\/code><\/code> function will strip whitespace (or other characters) from the end of a string.<\/p>\n<h3>PHP <code>rtrim()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> rtrim ( string $str [, string $character_mask ] ) : string<\/code><\/pre>\n<h3>PHP <code>rtrim()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>character_mask<\/code> \u2014 You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>rtrim()<\/code> Return Value<\/h3>\n<p>The PHP <code>rtrim()<\/code> function returns the modified string.<\/p>\n<h3>PHP <code>rtrim()<\/code> Working Examples<\/h3>\n<h4>1. Usage example of rtrim()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = \"\\t\\tThese are a few words :) ...  \";\n$binary = \"\\x09Example string\\x0A\";\n$hello  = \"Hello World\";\nvar_dump($text, $binary, $hello);\nprint \"\\n\";\n$trimmed = rtrim($text);\nvar_dump($trimmed);\n$trimmed = rtrim($text, \" \\t.\");\nvar_dump($trimmed);\n$trimmed = rtrim($hello, \"Hdle\");\nvar_dump($trimmed);\n\/\/ trim the ASCII control characters at the end of $binary\n\/\/ (from 0 to 31 inclusive)\n$clean = rtrim($binary, \"\\x00..\\x1F\");\nvar_dump($clean);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(32) \" These are a few words :) ... \"\nstring(16) \" Example string\n\"\nstring(11) \"Hello World\"\nstring(30) \" These are a few words :) ...\"\nstring(26) \" These are a few words :)\"\nstring(9) \"Hello Wor\"\nstring(15) \" Example string\"<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: pinkgothic<\/p>\n<pre><code class=\"lang-php\">I have an obsessive love for php's array functions given how extremely easy they've made complex string handling for me in various situations... so, have another string-rtrim() variant: \n \n&lt;?php \n \nfunction strrtrim($message, $strip) { \n    \/\/ break message apart by strip string \n    $lines = explode($strip, $message); \n    $last  = ''; \n    \/\/ pop off empty strings at the end \n    do { \n        $last = array_pop($lines); \n    } while (empty($last) &amp;&amp; (count($lines))); \n    \/\/ re-assemble what remains \n    return implode($strip, array_merge($lines, array($last))); \n} \n \n?&gt; \n \nAstonishingly, something I didn't expect, but: It completely compares to harmor's rstrtrim below, execution time wise. o_o Whee!<\/code><\/pre>\n<p>Contributed By: gbelanger<\/p>\n<pre><code class=\"lang-php\">True, the Perl chomp() will only trim newline characters. There is, however, the Perl chop() function which is pretty much identical to the PHP rtrim() \n \n--- \n \nHere's a quick way to recursively trim every element of an array, useful after the file() function : \n \n&lt;?php \n# Reads \/etc\/passwd file an trims newlines on each entry \n$aFileContent = file(\"\/etc\/passwd\"); \nforeach ($aFileContent as $sKey =&gt; $sValue) { \n    $aFileContent[$sKey] = rtrim($sValue); \n} \n \nprint_r($aFileContent); \n?&gt;<\/code><\/pre>\n<p>Contributed By: todd<\/p>\n<pre><code class=\"lang-php\">This shows how rtrim works when using the optional charlist parameter:\nrtrim reads a character, one at a time, from the optional charlist parameter and compares it to the end of the str string. If the characters match, it trims it off and starts over again, looking at the \"new\" last character in the str string and compares it to the first character in the charlist again. If the characters do not match, it moves to the next character in the charlist parameter comparing once again. It continues until the charlist parameter has been completely processed, one at a time, and the str string no longer contains any matches. The newly \"rtrimmed\" string is returned.\n&lt;?php\n  \/\/ Example 1:\n  rtrim('This is a short short sentence', 'short sentence');\n  \/\/ returns 'This is a'\n  \/\/ If you were expecting the result to be 'This is a short ',\n  \/\/ then you're wrong; the exact string, 'short sentence',\n  \/\/ isn't matched.  Remember, character-by-character comparison!\n  \/\/ Example 2:\n  rtrim('This is a short short sentence', 'cents');\n  \/\/ returns 'This is a short short '\n?&gt;<\/code><\/pre>\n<p>Contributed By: pinkgothic<\/p>\n<pre><code class=\"lang-php\">On the recurring subject of string-stripping instead of character-stripping rtrim() implementations... the simplest (with a caveat) is probably the basename() function. It has a second parameter that functions as a right-trim using whole strings:\n&lt;?php\necho basename('MooFoo', 'Foo');\n?&gt;\n...outputs 'Moo'.\nSince it also strips anything that looks like a directory, it's not quite identical with hacking a string off the end:\n&lt;?php\necho basename('Zoo\/MooFoo', 'Foo');\n?&gt;\n...still outputs 'Moo'.\nBut sometimes it gets the job done.<\/code><\/pre>\n<p>Contributed By: Unimagined<\/p>\n<pre><code class=\"lang-php\">I needed a way to trim all white space and then a few chosen strings from the end of a string.  So I wrote this class to reuse when stuff needs to be trimmed.  \n&lt;?php\nclass cleaner {\nfunction cleaner ($cuts,$pinfo) {\n$ucut = \"0\";\n$lcut = \"0\";\nwhile ($cuts[$ucut]) {\n$lcut++;\n$ucut++;\n}\n$lcut = $lcut - 1;\n$ucut = \"0\";\n$rcut = \"0\";\n$wiy = \"start\";\nwhile ($wiy) {\nif ($so) {\n$ucut = \"0\";\n$rcut = \"0\";\nunset($so);\n}\nif (!$cuts[$ucut]) {\n$so = \"restart\";\n} else {\n$pinfo = rtrim($pinfo);\n$bpinfol = strlen($pinfo);\n$tcut = $cuts[$ucut];\n$pinfo = rtrim($pinfo,\"$tcut\");\n$pinfol = strlen($pinfo);\n    if ($bpinfol == $pinfol) {\n    $rcut++;\n    if ($rcut == $lcut) {\n    unset($wiy);\n    }\n    $ucut++;\n    } else {\n    $so = \"restart\";\n    }\n}\n}\n$this-&gt;cleaner = $pinfo;\n}\n}\n$pinfo = \"Well... I'm really bored...&lt;br \/&gt;&lt;br&gt;&amp;nbsp;    \\n\\t&amp;nbsp;&lt;br&gt;&lt;br \/&gt;&lt;br&gt;&amp;nbsp;    \\r\\r&amp;nbsp;&lt;br&gt;\\r&lt;br \/&gt;&lt;br&gt;\\r&amp;nbsp;    &amp;nbsp;\\n&lt;br&gt;      &lt;br \/&gt;\\t\";\n$cuts = array('\\n','\\r','\\t',' ',' ','&amp;nbsp;','&lt;br \/&gt;','&lt;br&gt;','&lt;br\/&gt;');\n$pinfo = new cleaner($cuts,$pinfo);\n$pinfo = $pinfo-&gt;cleaner;\nprint $pinfo;\n?&gt;\nThat class will take any string that you put in the $cust array and remove it from the end of the $pinfo string.  It's useful for cleaning up comments, articles, or mail that users post to your site, making it so there's no extra blank space or blank lines.<\/code><\/pre>\n<h2 id=\"setlocale\">PHP <code>setlocale()<\/code> Function<\/h2>\n<h3>What does <code>setlocale()<\/code> do?<\/h3>\n<p>The PHP <code><code>setlocale()<\/code><\/code> function will sets locale information.<\/p>\n<h3>PHP <code>setlocale()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> setlocale ( int $category , string $locale [, string $... ] ) : string<\/code><\/pre>\n<pre><code class=\"lang-php\"> setlocale ( int $category , array $locale ) : string<\/code><\/pre>\n<h3>PHP <code>setlocale()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>category<\/code> \u2014 category is a named constant specifying the category of the functions affected by the locale setting: <\/p>\n<\/li>\n<li>\n<p><code>locale<\/code> \u2014 If locale is NULL or the empty string &#8220;&#8221;, the locale names will be set from the values of environment variables with the same names as the above categories, or from &#8220;LANG&#8221;. <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 (Optional string or array parameters to try as locale settings until success.) <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>setlocale()<\/code> Return Value<\/h3>\n<p>The PHP <code>setlocale()<\/code> function returns the new current locale, or <code>FALSE<\/code> if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.<\/p>\n<h3>PHP <code>setlocale()<\/code> Working Examples<\/h3>\n<h4>1. setlocale() Examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/* Set locale to Dutch *\/\nsetlocale(LC_ALL, 'nl_NL');\n\/* Output: vrijdag 22 december 1978 *\/\necho strftime(\"%A %e %B %Y\", mktime(0, 0, 0, 12, 22, 1978));\n\/* try different possible locale names for german *\/\n$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');\necho \"Preferred locale for german on this system is '$loc_de'\";\n?&gt;<\/code><\/pre>\n<h4>2. setlocale() Examples for Windows<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/* Set locale to Dutch *\/\nsetlocale(LC_ALL, 'nld_nld');\n\/* Output: vrijdag 22 december 1978 *\/\necho strftime(\"%A %d %B %Y\", mktime(0, 0, 0, 12, 22, 1978));\n\/* try different possible locale names for german *\/\n$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');\necho \"Preferred locale for german on this system is '$loc_de'\";\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP setlocale()<\/code> Function<\/h3>\n<p><strong>7.0.0 \u2014 <\/strong> Support for the <code class=\"parameter\">category<\/code> parameter passed as a string has been removed. Only LC_* constants can be used as of this version. <\/p>\n<p><strong>5.3.0 \u2014 <\/strong> This function now throws an <code>E_DEPRECATED<\/code> notice if a string is passed to the <code class=\"parameter\">category<\/code> parameter instead of one of the LC_* constants. <\/p>\n<h3>Important Points about PHP <code>setlocale()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called <code>setlocale()<\/code>. This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using <code>setlocale()<\/code>. <\/p>\n<\/li>\n<li>\n<p> On Windows, setlocale(LC_ALL, &#8221;) sets the locale names from the system&#8217;s regional\/language settings (accessible via Control Panel). <\/p>\n<\/li>\n<li>\n<p> The return value of <code>setlocale()<\/code> depends on the system that PHP is running. It returns exactly what the system <strong>setlocale<\/strong> function returns. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: r dot nospam dot velseboer<\/p>\n<pre><code class=\"lang-php\">Be careful with the LC_ALL setting, as it may introduce some unwanted conversions. For example, I used \nsetlocale (LC_ALL, \"Dutch\");\nto get my weekdays in dutch on the page. From that moment on (as I found out many hours later) my floating point values from MYSQL where interpreted as integers because the Dutch locale wants a comma (,) instead of a point (.) before the decimals. I tried printf, number_format, floatval.... all to no avail. 1.50 was always printed as 1.00 :(\nWhen I set my locale to :\n setlocale (LC_TIME, \"Dutch\");\nmy weekdays are good now and my floating point values too. \nI hope I can save some people the trouble of figuring this out by themselves.\nRob<\/code><\/pre>\n<p>Contributed By: russ<\/p>\n<pre><code class=\"lang-php\">If you are looking for a getlocale() function simply pass 0 (zero) as the second parameter to setlocale().\nBeware though if you use the category LC_ALL and some of the locales differ as a string containing all the locales is returned:\n&lt;?php\necho setlocale(LC_ALL, 0);\n\/\/ LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;\n\/\/ LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C\necho setlocale(LC_CTYPE, 0);\n\/\/ en_US.UTF-8\nsetlocale(LC_ALL, \"en_US.UTF-8\");\necho setlocale(LC_ALL, 0);\n\/\/ en_US.UTF-8\n?&gt;\nIf you are looking to store and reset the locales you could do something like this:\n&lt;?php\n$originalLocales = explode(\";\", setlocale(LC_ALL, 0));\nsetlocale(LC_ALL, \"nb_NO.utf8\");\n\/\/ Do something\nforeach ($originalLocales as $localeSetting) {\n  if (strpos($localeSetting, \"=\") !== false) {\n    list ($category, $locale) = explode(\"=\", $localeSetting);\n  }\n  else {\n    $category = LC_ALL;\n    $locale   = $localeSetting;\n  }\n  setlocale($category, $locale); \n}\n?&gt;\nThe above works here (Ubuntu Linux) but as the setlocale() function is just wrapping the equivalent system calls, your mileage may vary on the result.<\/code><\/pre>\n<p>Contributed By: Kari Sderholm aka Haprog<\/p>\n<pre><code class=\"lang-php\">It took me a while to figure out how to get a Finnish locale correctly set on Ubuntu Server with Apache2 and PHP5.\nAt first the output for \"locale -a\" was this:\nC\nen_US.utf8\nPOSIX\nI had to install a finnish language pack with\n\"sudo apt-get install language-pack-fi-base\"\nNow the output for \"locale -a\" is:\nC\nen_US.utf8\nfi_FI.utf8\nPOSIX\nThe last thing you need to do after installing the correct language pack is restart Apache with \"sudo apache2ctl restart\". The locale \"fi_FI.utf8\" can then be used in PHP5 after restarting Apache.\nFor setting Finnish timezone and locale in PHP use:\n&lt;?php\ndate_default_timezone_set('Europe\/Helsinki');\nsetlocale(LC_ALL, array('fi_FI.UTF-8','fi_FI@euro','fi_FI','finnish'));\n?&gt;<\/code><\/pre>\n<h2 id=\"sha1\">PHP <code>sha1()<\/code> Function<\/h2>\n<h3>What does <code>sha1()<\/code> do?<\/h3>\n<p>The PHP <code><code>sha1()<\/code><\/code> function will calculates the sha1 hash of <code class=\"parameter\">str<\/code> using the \u00bb US Secure Hash Algorithm 1.<\/p>\n<h3>PHP <code>sha1()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> sha1 ( string $str [, bool $raw_output = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>sha1()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>raw_output<\/code> \u2014 If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>sha1()<\/code> Return Value<\/h3>\n<p>The PHP <code>sha1()<\/code> function returns the sha1 hash as a string.<\/p>\n<h3>PHP <code>sha1()<\/code> Working Examples<\/h3>\n<h4>1. A sha1() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = 'apple';\nif (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {\n    echo \"Would you like a green or red apple?\";\n}\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>sha1()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See the Password Hashing FAQ for details and best practices. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">The suggestion below to double-hash your password is not a good idea.  You are much much better off adding a variable salt to passwords before hashing (such as the username or other field that is dissimilar for every account).\nDouble hashing is *worse* security than a regular hash.  What you're actually doing is taking some input $passwd, converting it to a string of exactly 32 characters containing only the characters [0-9][A-F], and then hashing *that*. You have just *greatly* increased the odds of a hash collision (ie. the odds that I can guess a phrase that will hash to the same value as your password).\nsha1(md5($pass)) makes even less sense, since you're feeding in 128-bits of information to generate a 256-bit hash, so 50% of the resulting data is redundant.  You have not increased security at all.<\/code><\/pre>\n<h2 id=\"sha1_file\">PHP <code>sha1_file()<\/code> Function<\/h2>\n<h3>What does <code>sha1_file()<\/code> do?<\/h3>\n<p>The PHP <code><code>sha1_file()<\/code><\/code> function will give you that hash. The hash is a 40-character hexadecimal number.<\/p>\n<h3>PHP <code>sha1_file()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> sha1_file ( string $filename [, bool $raw_output = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>sha1_file()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>filename<\/code> \u2014 The filename of the file to hash. <\/p>\n<\/li>\n<li>\n<p><code>raw_output<\/code> \u2014 When TRUE, returns the digest in raw binary format with a length of 20. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>sha1_file()<\/code> Return Value<\/h3>\n<p>The PHP <code>sha1_file()<\/code> function returns a string on success, <code>FALSE<\/code> otherwise.<\/p>\n<h3>PHP <code>sha1_file()<\/code> Working Examples<\/h3>\n<h4>1. sha1_file() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nforeach(glob('\/home\/Kalle\/myproject\/*.php') as $ent)\n{\n    if(is_dir($ent))\n    {\n        continue;\n    }\n    echo $ent . ' (SHA1: ' . sha1_file($ent) . ')', PHP_EOL;\n}\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP sha1_file()<\/code> Function<\/h3>\n<p><strong>5.1.0 \u2014 <\/strong> Changed the function to use the streams API. It means that you can use it with wrappers, like sha1_file(&#8216;http:\/\/example.com\/..&#8217;) <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: xijque<\/p>\n<pre><code class=\"lang-php\">Just for the record - \nAs some have pointed out, you have two ways to generate the hash of a file:\nMethod 1 [this function]: sha1_file($file)\nMethod 2: sha1(file_get_contents($file))\nIt's important to realize that these two methods are NOT the same thing. If they were, I seriously doubt this function would exist.\nThe key difference, as far as I can tell, is how the file's contents are loaded. The second method loads the entirety of $file into memory before passing it to sha1($str). Method two, however, loads the contents of $file as they are needed to create the hash.\nIf you can guarantee that you'll only ever have to hash relatively small files, this difference means very little. If you have larger ones, though, loading the entirety of file into memory is a bad idea: best case, you slow down your server as it tries to handle the request; worse case, you run out of memory and don't get your hash at all.\nJust try to keep this in mind if you decide to load the file's contents yourself, in lieu of using this function. On my system, I was able to use this function to generate the hash of a 2.6GB file in 22 seconds, whereas I could not with the second method, due to an out-of-memory error (which took 185 seconds).<\/code><\/pre>\n<h2 id=\"similar_text\">PHP <code>similar_text()<\/code> Function<\/h2>\n<h3>What does <code>similar_text()<\/code> do?<\/h3>\n<p>The PHP <code><code>similar_text()<\/code><\/code> function will calculate the similarity between two strings.<\/p>\n<h3>PHP <code>similar_text()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> similar_text ( string $first , string $second [, float &$percent ] ) : int<\/code><\/pre>\n<h3>PHP <code>similar_text()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>first<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>second<\/code> \u2014 The second string. <\/p>\n<\/li>\n<li>\n<p><code>percent<\/code> \u2014 By passing a reference as third argument, <code>similar_text()<\/code> will calculate the similarity in percent, by dividing the result of <code>similar_text()<\/code> by the average of the lengths of the given strings times 100. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>similar_text()<\/code> Return Value<\/h3>\n<p>The PHP <code>similar_text()<\/code> function returns the number of matching chars in both strings.<\/p>\n<h3>PHP <code>similar_text()<\/code> Working Examples<\/h3>\n<h4>1. similar_text() argument swapping example<\/h4>\n<pre><code class=\"lang-php\">first<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">similarity: 5 (71.428571428571 %)\nsimilarity: 3 (42.857142857143 %)<\/code><\/pre>\n<h3>Important Points about PHP <code>similar_text()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Swapping the <code class=\"parameter\">first<\/code> and <code class=\"parameter\">second<\/code> may yield a different result; see the example below. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">Hey there, \n \nBe aware when using this function, that the order of passing the strings is very important if you want to calculate the percentage of similarity, in fact, altering the variables will give a very different result, example : \n \n&lt;?php \n$var_1 = 'PHP IS GREAT'; \n$var_2 = 'WITH MYSQL'; \n \nsimilar_text($var_1, $var_2, $percent); \n \necho $percent; \n\/\/ 27.272727272727 \n \nsimilar_text($var_2, $var_1, $percent); \n \necho $percent; \n\/\/ 18.181818181818 \n?&gt;<\/code><\/pre>\n<p>Contributed By: daniel dot karbach<\/p>\n<pre><code class=\"lang-php\">Please note that this function calculates a similarity of 0 (zero) for two empty strings.\n&lt;?php\nsimilar_text(\"\", \"\", $sim);\necho $sim; \/\/ \"0\"\n?&gt;<\/code><\/pre>\n<p>Contributed By: vasyl<\/p>\n<pre><code class=\"lang-php\">Recursive algorithm usually is very elegant one. I found a way to get better precision without the recursion. Imagine two different (or same) length ribbons with letters on each. You simply shifting one ribbon to left till it matches the letter the first.\n&lt;?php\nfunction similarity($str1, $str2) {\n    $len1 = strlen($str1);\n    $len2 = strlen($str2);\n    \n    $max = max($len1, $len2);\n    $similarity = $i = $j = 0;\n    \n    while (($i &lt; $len1) &amp;&amp; isset($str2[$j])) {\n        if ($str1[$i] == $str2[$j]) {\n            $similarity++;\n            $i++;\n            $j++;\n        } elseif ($len1 &lt; $len2) {\n            $len1++;\n            $j++;\n        } elseif ($len1 &gt; $len2) {\n            $i++;\n            $len1--;\n        } else {\n            $i++;\n            $j++;\n        }\n    }\n    return round($similarity \/ $max, 2);\n}\n$str1 = '12345678901234567890';\n$str2 = '12345678991234567890';\necho 'Similarity: ' . (similarity($str1, $str2) * 100) . '%';\n?&gt;<\/code><\/pre>\n<p>Contributed By: ryan<\/p>\n<pre><code class=\"lang-php\">Note that this function is case sensitive:\n&lt;?php\n$var1 = 'Hello';\n$var2 = 'Hello';\n$var3 = 'hello';\necho similar_text($var1, $var2);  \/\/ 5\necho similar_text($var1, $var3);  \/\/ 4<\/code><\/pre>\n<h2 id=\"soundex\">PHP <code>soundex()<\/code> Function<\/h2>\n<h3>What does <code>soundex()<\/code> do?<\/h3>\n<p>The PHP <code><code>soundex()<\/code><\/code> function will calculates the soundex key of <code class=\"parameter\">str<\/code>.<\/p>\n<h3>PHP <code>soundex()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> soundex ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>soundex()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>soundex()<\/code> Return Value<\/h3>\n<p>The PHP <code>soundex()<\/code> function returns the soundex key as a string.<\/p>\n<h3>PHP <code>soundex()<\/code> Working Examples<\/h3>\n<h4>1. Soundex Examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nsoundex(\"Euler\")       == soundex(\"Ellery\");    \/\/ E460\nsoundex(\"Gauss\")       == soundex(\"Ghosh\");     \/\/ G200\nsoundex(\"Hilbert\")     == soundex(\"Heilbronn\"); \/\/ H416\nsoundex(\"Knuth\")       == soundex(\"Kant\");      \/\/ K530\nsoundex(\"Lloyd\")       == soundex(\"Ladd\");      \/\/ L300\nsoundex(\"Lukasiewicz\") == soundex(\"Lissajous\"); \/\/ L222\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: nicolas dot zimmer<\/p>\n<pre><code class=\"lang-php\">Since soundex() does not produce optimal results for German language\nwe have written a function to implement the so called K\u00f6lner Phonetik\n(Cologne Phonetic).\nPlease find the code below in the hope it might be useful:\n&lt;?php\n\/**\n * A function for retrieving the K\u00f6lner Phonetik value of a string\n * \n * As described at http:\/\/de.wikipedia.org\/wiki\/K\u00f6lner_Phonetik\n * Based on Hans Joachim Postel: Die K\u00f6lner Phonetik. \n * Ein Verfahren zur Identifizierung von Personennamen auf der \n * Grundlage der Gestaltanalyse. \n * in: IBM-Nachrichten, 19. Jahrgang, 1969, S. 925-931\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * @package phonetics\n * @version 1.0\n * @link http:\/\/www.einfachmarke.de\n * @license GPL 3.0 &lt;http:\/\/www.gnu.org\/licenses\/&gt;\n * @copyright  2008 by einfachmarke.de\n * @author Nicolas Zimmer &lt;nicolas dot zimmer at einfachmarke.de&gt;\n *\/\nfunction cologne_phon($word){\n    \n  \/**\n  * @param  string  $word string to be analyzed\n  * @return string  $value represents the K\u00f6lner Phonetik value\n  * @access public\n  *\/\n  \n    \/\/prepare for processing\n    $word=strtolower($word);\n    $substitution=array(\n            \"\u00e4\"=&gt;\"a\",\n            \"\u00f6\"=&gt;\"o\",\n            \"\u00fc\"=&gt;\"u\",\n            \"\u00df\"=&gt;\"ss\",\n            \"ph\"=&gt;\"f\"\n            );\n    foreach ($substitution as $letter=&gt;$substitution) {\n        $word=str_replace($letter,$substitution,$word);\n    }\n    \n    $len=strlen($word);\n    \n    \/\/Rule for exeptions\n    $exceptionsLeading=array(\n    4=&gt;array(\"ca\",\"ch\",\"ck\",\"cl\",\"co\",\"cq\",\"cu\",\"cx\"),\n    8=&gt;array(\"dc\",\"ds\",\"dz\",\"tc\",\"ts\",\"tz\")\n    );\n    \n    $exceptionsFollowing=array(\"sc\",\"zc\",\"cx\",\"kx\",\"qx\");\n    \n    \/\/Table for coding\n    $codingTable=array(\n    0=&gt;array(\"a\",\"e\",\"i\",\"j\",\"o\",\"u\",\"y\"),\n    1=&gt;array(\"b\",\"p\"),\n    2=&gt;array(\"d\",\"t\"),\n    3=&gt;array(\"f\",\"v\",\"w\"),\n    4=&gt;array(\"c\",\"g\",\"k\",\"q\"),\n    48=&gt;array(\"x\"),\n    5=&gt;array(\"l\"),\n    6=&gt;array(\"m\",\"n\"),\n    7=&gt;array(\"r\"),\n    8=&gt;array(\"c\",\"s\",\"z\"),\n    );\n    \n    for ($i=0;$i&lt;$len;$i++){\n        $value[$i]=\"\";\n        \n        \/\/Exceptions\n        if ($i==0 AND $word[$i].$word[$i+1]==\"cr\") $value[$i]=4;\n        \n        foreach ($exceptionsLeading as $code=&gt;$letters) {\n            if (in_array($word[$i].$word[$i+1],$letters)){\n                    $value[$i]=$code;\n}                }\n        \n        if ($i!=0 AND (in_array($word[$i-1].$word[$i], \n$exceptionsFollowing))) {\n            value[$i]=8;        \n}                \n        \n        \/\/Normal encoding\n        if ($value[$i]==\"\"){\n                foreach ($codingTable as $code=&gt;$letters) {\n                    if (in_array($word[$i],$letters))$value[$i]=$code;\n                }\n            }\n        }\n    \n    \/\/delete double values\n    $len=count($value);\n    \n    for ($i=1;$i&lt;$len;$i++){\n        if ($value[$i]==$value[$i-1]) $value[$i]=\"\";\n    }\n    \n    \/\/delete vocals \n    for ($i=1;$i&gt;$len;$i++){\/\/omitting first characer code and h\n        if ($value[$i]==0) $value[$i]=\"\";\n    }\n    \n    \n    $value=array_filter($value);\n    $value=implode(\"\",$value);\n    \n    return $value;\n    \n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: Dirk Hoeschen &#8211; Feenders de<\/p>\n<pre><code class=\"lang-php\">I made some improvements to the \"Cologne Phonetic\" function of niclas zimmer. Key and value of the arrays are inverted to uses simple arrays instead of multidimensional arrays. Therefore all loops and iterations are not longer necessary to find the matching value  for a char.\nI put the function into a static class and moved the array declarations outside the function.\nThe result is more reliable and five times faster than the original.\n&lt;?php   \nclass CologneHash() {\n    static $eLeading = array(\"ca\" =&gt; 4, \"ch\" =&gt; 4, \"ck\" =&gt; 4, \"cl\" =&gt; 4, \"co\" =&gt; 4, \"cq\" =&gt; 4, \"cu\" =&gt; 4, \"cx\" =&gt; 4, \"dc\" =&gt; 8, \"ds\" =&gt; 8, \"dz\" =&gt; 8, \"tc\" =&gt; 8, \"ts\" =&gt; 8, \"tz\" =&gt; 8); \n    static $eFollow = array(\"sc\", \"zc\", \"cx\", \"kx\", \"qx\");\n    static $codingTable = array(\"a\" =&gt; 0, \"e\" =&gt; 0, \"i\" =&gt; 0, \"j\" =&gt; 0, \"o\" =&gt; 0, \"u\" =&gt; 0, \"y\" =&gt; 0,\n        \"b\" =&gt; 1, \"p\" =&gt; 1, \"d\" =&gt; 2, \"t\" =&gt; 2, \"f\" =&gt; 3, \"v\" =&gt; 3, \"w\" =&gt; 3, \"c\" =&gt; 4, \"g\" =&gt; 4, \"k\" =&gt; 4, \"q\" =&gt; 4,\n        \"x\" =&gt; 48, \"l\" =&gt; 5, \"m\" =&gt; 6, \"n\" =&gt; 6, \"r\" =&gt; 7, \"c\" =&gt; 8, \"s\" =&gt; 8, \"z\" =&gt; 8);\n    public static function getCologneHash($word)\n    {\n        if (empty($word)) return false;\n        $len = strlen($word);\n \n        for ($i = 0; $i &lt; $len; $i++) {\n            $value[$i] = \"\";\n \n            \/\/Exceptions\n            if ($i == 0 &amp;&amp; $word[$i] . $word[$i + 1] == \"cr\") {\n                $value[$i] = 4;\n            }\n \n            if (isset($word[$i + 1]) &amp;&amp; isset(self::$eLeading[$word[$i] . $word[$i + 1]])) {\n                $value[$i] = self::$eLeading[$word[$i] . $word[$i + 1]];\n            }\n            if ($i != 0 &amp;&amp; (in_array($word[$i - 1] . $word[$i], self::$eFollow))) {\n                $value[$i] = 8;\n            }\n \n            \/\/ normal encoding\n            if ($value[$i]==\"\") {\n                if (isset(self::$codingTable[$word[$i]])) {\n                    $value[$i] = self::$codingTable[$word[$i]];\n                }\n            }\n        }\n        \/\/ delete double values\n        $len = count($value);\n \n        for ($i = 1; $i &lt; $len; $i++) {\n            if ($value[$i] == $value[$i - 1]) {\n                $value[$i] = \"\";\n            }\n        }\n \n        \/\/ delete vocals\n        for ($i = 1; $i &gt; $len; $i++) {\n            \/\/ omitting first characer code and h\n            if ($value[$i] == 0) {\n                $value[$i] = \"\";\n            }\n        }\n \n        $value = array_filter($value);\n        $value = implode(\"\", $value);\n \n        return $value;\n    }\n \n}\n?&gt;<\/code><\/pre>\n<h2 id=\"sprintf\">PHP <code>sprintf()<\/code> Function<\/h2>\n<h3>What does <code>sprintf()<\/code> do?<\/h3>\n<p>The PHP <code><code>sprintf()<\/code><\/code> function will give you a string produced according to the formatting string <code class=\"parameter\">format<\/code>.<\/p>\n<h3>PHP <code>sprintf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> sprintf ( string $format [, mixed $... ] ) : string<\/code><\/pre>\n<h3>PHP <code>sprintf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>sprintf()<\/code> Return Value<\/h3>\n<p>The PHP <code>sprintf()<\/code> function returns a string produced according to the formatting string <code class=\"parameter\">format<\/code>, or <code>FALSE<\/code> on failure.<\/p>\n<h3>PHP <code>sprintf()<\/code> Working Examples<\/h3>\n<h4>1. Argument swapping<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$num = 5;\n$location = 'tree';\n$format = 'There are %d monkeys in the %s';\necho sprintf($format, $num, $location);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">There are 5 monkeys in the tree<\/code><\/pre>\n<h4>2. Specifying padding character<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho sprintf(\"%'.9d\\n\", 123);\necho sprintf(\"%'.09d\\n\", 123);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">......123\n000000123<\/code><\/pre>\n<h4>3. Position specifier with other specifiers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$format = 'The %2$s contains %1$04d monkeys';\necho sprintf($format, $num, $location);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">The tree contains 0005 monkeys<\/code><\/pre>\n<h4>4. sprintf(): zero-padded integers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$isodate = sprintf(\"%04d-%02d-%02d\", $year, $month, $day);\n?&gt;<\/code><\/pre>\n<h4>5. sprintf(): formatting currency<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$money1 = 68.75;\n$money2 = 54.35;\n$money = $money1 + $money2;\necho $money;\necho \"\\n\";\n$formatted = sprintf(\"%01.2f\", $money);\necho $formatted;\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">123.1\n123.10<\/code><\/pre>\n<h4>6. sprintf(): scientific notation<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$number = 362525200;\necho sprintf(\"%.3e\", $number);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">3.625e+8<\/code><\/pre>\n<h3>Important Points about PHP <code>sprintf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Alex R. Gibbs<\/p>\n<pre><code class=\"lang-php\">1.  A plus sign ('+') means put a '+' before positive numbers while a minus sign ('-') means left justify.  The documentation incorrectly states that they are interchangeable.  They produce unique results that can be combined:\n&lt;?php\necho sprintf (\"|%+4d|%+4d|\\n\",   1, -1);\necho sprintf (\"|%-4d|%-4d|\\n\",   1, -1);\necho sprintf (\"|%+-4d|%+-4d|\\n\", 1, -1);\n?&gt;\noutputs:\n|  +1|  -1|\n|1   |-1  |\n|+1  |-1  |\n2.  Padding with a '0' is different than padding with other characters.  Zeros will only be added at the front of a number, after any sign.  Other characters will be added before the sign, or after the number:\n&lt;?php\necho sprintf (\"|%04d|\\n\",   -2);\necho sprintf (\"|%':4d|\\n\",  -2);\necho sprintf (\"|%-':4d|\\n\", -2);\n\/\/ Specifying both \"-\" and \"0\" creates a conflict with unexpected results:\necho sprintf (\"|%-04d|\\n\",  -2);\n\/\/ Padding with other digits behaves like other non-zero characters:\necho sprintf (\"|%-'14d|\\n\", -2);\necho sprintf (\"|%-'04d|\\n\", -2);\n?&gt;\noutputs:\n|-002|\n|::-2|\n|-2::|\n|-2  |\n|-211|\n|-2  |<\/code><\/pre>\n<p>Contributed By: remy dot damour<\/p>\n<pre><code class=\"lang-php\">With printf() and sprintf() functions, escape character is not backslash '\\' but rather '%'.\nIe. to print '%' character you need to escape it with itself:\n&lt;?php\nprintf('%%%s%%', 'koko'); #output: '%koko%'\n?&gt;<\/code><\/pre>\n<p>Contributed By: kontakt<\/p>\n<pre><code class=\"lang-php\">There are already some comments on using sprintf to force leading leading zeros but the examples only include integers. I needed leading zeros on floating point numbers and was surprised that it didn't work as expected.\nExample:\n&lt;?php\nsprintf('%02d', 1);\n?&gt;\nThis will result in 01. However, trying the same for a float with precision doesn't work:\n&lt;?php\nsprintf('%02.2f', 1);\n?&gt;\nYields 1.00. \nThis threw me a little off. To get the desired result, one needs to add the precision (2) and the length of the decimal seperator \".\" (1). So the correct pattern would be\n&lt;?php\nsprintf('%05.2f', 1);\n?&gt;\nOutput: 01.00\nPlease see http:\/\/stackoverflow.com\/a\/28739819\/413531 for a more detailed explanation.<\/code><\/pre>\n<p>Contributed By: jfgrissom<\/p>\n<pre><code class=\"lang-php\">I had a nightmare trying to find the two's complement of a 32 bit number.\nI got this from http:\/\/www.webmasterworld.com\/forum88\/13334.htm (credit where credit is due... =P  )\nQuote: ...find out the 2's complement of any number, which is -(pow(2, n) - N) where n is the number of bits and N is the number for which to find out its 2's complement.\nThis worked magic for me... previously I was trying to use\nsprintf (\"%b\",$32BitDecimal);\nBut it always returned 10000000000000000000000 when the $32BitDecimal value got above 2,000,000,000.\nThis -(pow(2, n) - N)\nWorked remarkably well and was very accurate.\nHope this helps someone fighting with two's complement in PHP.<\/code><\/pre>\n<p>Contributed By: Jay Gilford<\/p>\n<pre><code class=\"lang-php\">I created this function a while back to save on having to combine mysql_real_escape_string onto all the params passed into a sprintf. it works literally the same as the sprintf other than that it doesn't require you to escape your inputs. Hope its of some use to people\n&lt;?php\nfunction mressf()\n{\n    $args = func_get_args();\n    if (count($args) &lt; 2)\n        return false;\n    $query = array_shift($args);\n    $args = array_map('mysql_real_escape_string', $args);\n    array_unshift($args, $query);\n    $query = call_user_func_array('sprintf', $args);\n    return $query;\n}\n?&gt;\nRegards\nJay\nJaygilford.com<\/code><\/pre>\n<h2 id=\"sscanf\">PHP <code>sscanf()<\/code> Function<\/h2>\n<h3>What does <code>sscanf()<\/code> do?<\/h3>\n<p>The PHP <code><code>sscanf()<\/code><\/code> function will parses input from a string according to a format.<\/p>\n<h3>PHP <code>sscanf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> sscanf ( string $str , string $format [, mixed &$... ] ) : mixed<\/code><\/pre>\n<h3>PHP <code>sscanf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string being parsed. <\/p>\n<\/li>\n<li>\n<p><code>format<\/code> \u2014 The interpreted format for str, which is described in the documentation for <code>sprintf()<\/code> with following differences: <\/p>\n<\/li>\n<li>\n<p><code>...<\/code> \u2014 Optionally pass in variables by reference that will contain the parsed values. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>sscanf()<\/code> Return Value<\/h3>\n<p>The PHP <code>sscanf()<\/code> function returns d as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.<\/p>\n<h3>PHP <code>sscanf()<\/code> Working Examples<\/h3>\n<h4>1. sscanf() Example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ getting the serial number\nlist($serial) = sscanf(\"SN\/2350001\", \"SN\/%d\");\n\/\/ and the date of manufacturing\n$mandate = \"January 01 2000\";\nlist($month, $day, $year) = sscanf($mandate, \"%s %d %d\");\necho \"Item $serial was manufactured on: $year-\" . substr($month, 0, 3) . \"-$day\\n\";\n?&gt;<\/code><\/pre>\n<h4>2. sscanf() &#8211; using optional parameters<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ get author info and generate DocBook entry\n$auth = \"24\\tLewis Carroll\";\n$n = sscanf($auth, \"%d\\t%s %s\", $id, $first, $last);\necho \"&lt;author id='$id'&gt;\n    &lt;firstname&gt;$first&lt;\/firstname&gt;\n    &lt;surname&gt;$last&lt;\/surname&gt;\n&lt;\/author&gt;\\n\";\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jon<\/p>\n<pre><code class=\"lang-php\">This function is a great way to get integer rgb values from the html equivalent hex.\nlist($r, $g, $b) = sscanf('00ccff', '%2x%2x%2x');<\/code><\/pre>\n<p>Contributed By: mikewillitsgmail.com<\/p>\n<pre><code class=\"lang-php\">FYI - if you are trying to scan from a string which contains a filename with extension. For instance:\n&lt;?php\n$out = sscanf('file_name.gif', 'file_%s.%s', $fpart1, $fpart2);\n?&gt;\nThe scanned string in the $fpart1 parameter turns out to be 'name.gif' and $fpart2 will be NULL.\nTo get around this you can simply replace the \".\" with a space or another \"white-space like\" string sequence.\nI didn't see any other comments on regarding string literals which contain a '.' so I thought I'd mention it. The subtle characteristics of having \"white-space delimited\" content I think can be a source of usage contention. Obviously, another way to go is regular expressions in this instance, but for newer users this may be helpful.\nJust in case someone else spent 10 minutes of frustration like I did. This was seen on PHP Version 5.2.3-1ubuntu6.3.\nSearching the bug reports shows another users misunderstanding: http:\/\/bugs.php.net\/bug.php?id=7793<\/code><\/pre>\n<h2 id=\"str_getcsv\">PHP <code>str_getcsv()<\/code> Function<\/h2>\n<h3>What does <code>str_getcsv()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_getcsv()<\/code><\/code> function will give you an array containing the fields read.<\/p>\n<h3>PHP <code>str_getcsv()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_getcsv ( string $input [, string $delimiter = \",\" [, string $enclosure = '\"' [, string $escape = \"\\\\\" ]]] ) : array<\/code><\/pre>\n<h3>PHP <code>str_getcsv()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>input<\/code> \u2014 The string to parse. <\/p>\n<\/li>\n<li>\n<p><code>delimiter<\/code> \u2014 Set the field delimiter (one character only). <\/p>\n<\/li>\n<li>\n<p><code>enclosure<\/code> \u2014 Set the field enclosure character (one character only). <\/p>\n<\/li>\n<li>\n<p><code>escape<\/code> \u2014 Set the escape character (at most one character). Defaults as a backslash (\\) An empty string (&#8220;&#8221;) disables the proprietary escape mechanism. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_getcsv()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_getcsv()<\/code> function returns an indexed array containing the fields read.<\/p>\n<h3>Changelog for PHP str_getcsv()<\/code> Function<\/h3>\n<p><strong>7.4.0 \u2014 <\/strong> The <code class=\"parameter\">escape<\/code> parameter now interprets an empty string as signal to disable the proprietary escape mechanism. Formerly, an empty string was treated like the default parameter value. <\/p>\n<h3>Important Points about PHP <code>str_getcsv()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The locale settings are taken into account by this function. If <strong>LC_CTYPE<\/strong> is e.g. <strong>en_US.UTF-8<\/strong>, strings in one-byte encodings may be read wrongly by this function. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: james<\/p>\n<pre><code class=\"lang-php\">[Editor's Note (cmb): that does not produce the desired results, if fields contain linebreaks.] \n \nHandy one liner to parse a CSV file into an array \n \n&lt;?php \n \n$csv = array_map('str_getcsv', file('data.csv')); \n \n?&gt;<\/code><\/pre>\n<p>Contributed By: starrychloe<\/p>\n<pre><code class=\"lang-php\">Based on James' line, this will create an array of associative arrays with the first row column headers as the keys.\n&lt;?php\n    $csv = array_map('str_getcsv', file($file));\n    array_walk($csv, function(&amp;$a) use ($csv) {\n      $a = array_combine($csv[0], $a);\n    });\n    array_shift($csv); # remove column header\n?&gt; \nThis will yield something like\n    [2] =&gt; Array\n        (\n            [Campaign ID] =&gt; 295095038\n            [Ad group ID] =&gt; 22460178158\n            [Keyword ID] =&gt; 3993587178<\/code><\/pre>\n<p>Contributed By: durik<\/p>\n<pre><code class=\"lang-php\">As the str_getcsv(), unlike to fgetcsv(), does not parse the rows in CSV string, I have found following easy workaround: \n \n&lt;?php \n$Data = str_getcsv($CsvString, \"\\n\"); \/\/parse the rows \nforeach($Data as &amp;$Row) $Row = str_getcsv($Row, \";\"); \/\/parse the items in rows \n?&gt; \n \nWhy not use explode() instead of str_getcsv() to parse rows? Because explode() would not treat possible enclosured parts of string or escaped characters correctly.<\/code><\/pre>\n<p>Contributed By: Jay Williams<\/p>\n<pre><code class=\"lang-php\">Here is a quick and easy way to convert a CSV file to an associated array:\n&lt;?php\n\/**\n * @link http:\/\/gist.github.com\/385876\n *\/\nfunction csv_to_array($filename='', $delimiter=',')\n{\n    if(!file_exists($filename) || !is_readable($filename))\n        return FALSE;\n    $header = NULL;\n    $data = array();\n    if (($handle = fopen($filename, 'r')) !== FALSE)\n    {\n        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)\n        {\n            if(!$header)\n                $header = $row;\n            else\n                $data[] = array_combine($header, $row);\n        }\n        fclose($handle);\n    }\n    return $data;\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: Ryan Rubley<\/p>\n<pre><code class=\"lang-php\">@normadize - that is a nice start, but it fails on situations where a field is empty but quoted (returning a string with one double quote instead of an empty string) and cases like \"\"\"\"\"foo\"\"\"\"\" that should result in \"\"foo\"\" but instead return \"foo\". I also get a row with 1 empty field at the end because of the final CRLF in the CSV. Plus, I don't really like the !!Q!! magic or urlencoding to get around things. Also, \\R doesn't work in pcre on any of my php installations.\nHere is my take on this, without anonymous functions (so it works on PHP &lt; 5.3), and without your options (because I believe the only correct way to parse according to the RFC would be $skip_empty_lines = false and $trim_fields = false).\n\/\/parse a CSV file into a two-dimensional array\n\/\/this seems as simple as splitting a string by lines and commas, but this only works if tricks are performed\n\/\/to ensure that you do NOT split on lines and commas that are inside of double quotes.\nfunction parse_csv($str)\n{\n    \/\/match all the non-quoted text and one series of quoted text (or the end of the string)\n    \/\/each group of matches will be parsed with the callback, with $matches[1] containing all the non-quoted text,\n    \/\/and $matches[3] containing everything inside the quotes\n    $str = preg_replace_callback('\/([^\"]*)(\"((\"\"|[^\"])*)\"|$)\/s', 'parse_csv_quotes', $str);\n    \/\/remove the very last newline to prevent a 0-field array for the last line\n    $str = preg_replace('\/\\n$\/', '', $str);\n    \/\/split on LF and parse each line with a callback\n    return array_map('parse_csv_line', explode(\"\\n\", $str));\n}\n\/\/replace all the csv-special characters inside double quotes with markers using an escape sequence\nfunction parse_csv_quotes($matches)\n{\n    \/\/anything inside the quotes that might be used to split the string into lines and fields later,\n    \/\/needs to be quoted. The only character we can guarantee as safe to use, because it will never appear in the unquoted text, is a CR\n    \/\/So we're going to use CR as a marker to make escape sequences for CR, LF, Quotes, and Commas.\n    $str = str_replace(\"\\r\", \"\\rR\", $matches[3]);\n    $str = str_replace(\"\\n\", \"\\rN\", $str);\n    $str = str_replace('\"\"', \"\\rQ\", $str);\n    $str = str_replace(',', \"\\rC\", $str);\n    \/\/The unquoted text is where commas and newlines are allowed, and where the splits will happen\n    \/\/We're going to remove all CRs from the unquoted text, by normalizing all line endings to just LF\n    \/\/This ensures us that the only place CR is used, is as the escape sequences for quoted text\n    return preg_replace('\/\\r\\n?\/', \"\\n\", $matches[1]) . $str;\n}\n\/\/split on comma and parse each field with a callback\nfunction parse_csv_line($line)\n{\n    return array_map('parse_csv_field', explode(',', $line));\n}\n\/\/restore any csv-special characters that are part of the data\nfunction parse_csv_field($field) {\n    $field = str_replace(\"\\rC\", ',', $field);\n    $field = str_replace(\"\\rQ\", '\"', $field);\n    $field = str_replace(\"\\rN\", \"\\n\", $field);\n    $field = str_replace(\"\\rR\", \"\\r\", $field);\n    return $field;\n}<\/code><\/pre>\n<p>Contributed By: normadize -a- gmail -d- com<\/p>\n<pre><code class=\"lang-php\">Like some other users here noted, str_getcsv() cannot be used if you want to comply with either the RFC or with most spreadsheet tools like Excel or Google Docs.\nThese tools do not escape commas or new lines, but instead place double-quotes (\") around the field. If there are any double-quotes in the field, these are escaped with another double-quote (\" becomes \"\"). All this may look odd, but it is what the RFC and most tools do ... \nFor instance, try exporting as .csv a Google Docs spreadsheet (File &gt; Download as &gt; .csv) which has new lines and commas as part of the field values and see how the .csv content looks, then try to parse it using str_getcsv() ... it will spectacularly regardless of the arguments you pass to it.\nHere is a function that can handle everything correctly, and more:\n- doesn't use any for or while loops,\n- it allows for any separator (any string of any length),\n- option to skip empty lines,\n- option to trim fields,\n- can handle UTF8 data too (although .csv files are likely non-unicode).\nHere is the more human readable version of the function:\n&lt;?php\n\/\/ returns a two-dimensional array or rows and fields\nfunction parse_csv ($csv_string, $delimiter = \",\", $skip_empty_lines = true, $trim_fields = true)\n{\n    $enc = preg_replace('\/(?&lt;!\")\"\"\/', '!!Q!!', $csv_string);\n    $enc = preg_replace_callback(\n        '\/\"(.*?)\"\/s',\n        function ($field) {\n            return urlencode(utf8_encode($field[1]));\n        },\n        $enc\n    );\n    $lines = preg_split($skip_empty_lines ? ($trim_fields ? '\/( *\\R)+\/s' : '\/\\R+\/s') : '\/\\R\/s', $enc);\n    return array_map(\n        function ($line) use ($delimiter, $trim_fields) {\n            $fields = $trim_fields ? array_map('trim', explode($delimiter, $line)) : explode($delimiter, $line);\n            return array_map(\n                function ($field) {\n                    return str_replace('!!Q!!', '\"', utf8_decode(urldecode($field)));\n                },\n                $fields\n            );\n        },\n        $lines\n    );\n}\n?&gt;\nSince this is not using any loops, you can actually write it as a one-line statement (one-liner).\nHere's the function using just one line of code for the function body, formatted nicely though:\n&lt;?php\n\/\/ returns the same two-dimensional array as above, but with a one-liner code\nfunction parse_csv ($csv_string, $delimiter = \",\", $skip_empty_lines = true, $trim_fields = true)\n{\n    return array_map(\n        function ($line) use ($delimiter, $trim_fields) {\n            return array_map(\n                function ($field) {\n                    return str_replace('!!Q!!', '\"', utf8_decode(urldecode($field)));\n                },\n                $trim_fields ? array_map('trim', explode($delimiter, $line)) : explode($delimiter, $line)\n            );\n        },\n        preg_split(\n            $skip_empty_lines ? ($trim_fields ? '\/( *\\R)+\/s' : '\/\\R+\/s') : '\/\\R\/s',\n            preg_replace_callback(\n                '\/\"(.*?)\"\/s',\n                function ($field) {\n                    return urlencode(utf8_encode($field[1]));\n                },\n                $enc = preg_replace('\/(?&lt;!\")\"\"\/', '!!Q!!', $csv_string)\n            )\n        )\n    );\n}\n?&gt;\nReplace !!Q!! with another placeholder if you wish.\nHave fun.<\/code><\/pre>\n<p>Contributed By: dejiakala<\/p>\n<pre><code class=\"lang-php\">I wanted the best of the 2 solutions by james at moss dot io and Jay Williams (csv_to_array()) - create associative array from a CSV file with a header row.\n&lt;?php\n$array = array_map('str_getcsv', file('data.csv'));\n$header = array_shift($array);\narray_walk($array, '_combine_array', $header);\nfunction _combine_array(&amp;$row, $key, $header) {\n  $row = array_combine($header, $row);\n}\n?&gt;\nThen I thought why not try some benchmarking? I grabbed a sample CSV file with 50,000 rows (10 columns each) and Vulcan Logic Disassembler (VLD) which hooks into the Zend Engine and dumps all the opcodes (execution units) of a script - see http:\/\/pecl.php.net\/package\/vld and example here: http:\/\/fabien.potencier.org\/article\/8\/print-vs-echo-which-one-is-faster\nResult: \narray_walk() and array_map() - 39 opcodes\ncsv_to_array() - 69 opcodes<\/code><\/pre>\n<h2 id=\"str_ireplace\">PHP <code>str_ireplace()<\/code> Function<\/h2>\n<h3>What does <code>str_ireplace()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_ireplace()<\/code><\/code> function will case-insensitive version of <code>str_replace()<\/code>.<\/p>\n<h3>PHP <code>str_ireplace()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) : mixed<\/code><\/pre>\n<h3>PHP <code>str_ireplace()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>search<\/code> \u2014 The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. <\/p>\n<\/li>\n<li>\n<p><code>replace<\/code> \u2014 The replacement value that replaces found search values. An array may be used to designate multiple replacements. <\/p>\n<\/li>\n<li>\n<p><code>subject<\/code> \u2014 The string or array being searched and replaced on, otherwise known as the haystack. <\/p>\n<\/li>\n<li>\n<p><code>count<\/code> \u2014 If passed, this will be set to the number of replacements performed. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_ireplace()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_ireplace()<\/code> function returns a string or an array of replacements.<\/p>\n<h3>PHP <code>str_ireplace()<\/code> Working Examples<\/h3>\n<h4>1. str_ireplace() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$bodytag = str_ireplace(\"%body%\", \"black\", \"&lt;body text=%BODY%&gt;\");\necho $bodytag; \/\/ &lt;body text=black&gt;\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>str_ireplace()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Because <code>str_ireplace()<\/code> replaces left to right, it might replace a previously inserted value when doing multiple replacements. Example #2 in the <code>str_replace()<\/code> documentation demonstrates how this may affect you in practice. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: sawdust<\/p>\n<pre><code class=\"lang-php\">Here's a different approach to search result keyword highlighting that will match all keyword sub strings in a case insensitive manner and preserve case in the returned text. This solution first grabs all matches within $haystack in a case insensitive manner, and the secondly loops through each of those matched sub strings and applies a case sensitive replace in $haystack. This way each unique (in terms of case) instance of $needle is operated on individually allowing a case sensitive replace to be done in order to preserve the original case of each unique instance of $needle.\n&lt;?php\nfunction highlightStr($haystack, $needle, $highlightColorValue) {\n     \/\/ return $haystack if there is no highlight color or strings given, nothing to do.\n    if (strlen($highlightColorValue) &lt; 1 || strlen($haystack) &lt; 1 || strlen($needle) &lt; 1) {\n        return $haystack;\n    }\n    preg_match_all(\"\/$needle+\/i\", $haystack, $matches);\n    if (is_array($matches[0]) &amp;&amp; count($matches[0]) &gt;= 1) {\n        foreach ($matches[0] as $match) {\n            $haystack = str_replace($match, '&lt;span style=\"background-color:'.$highlightColorValue.';\"&gt;'.$match.'&lt;\/span&gt;', $haystack);\n        }\n    }\n    return $haystack;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"str_pad\">PHP <code>str_pad()<\/code> Function<\/h2>\n<h3>What does <code>str_pad()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_pad()<\/code><\/code> function will pad a string to a certain length with another string.<\/p>\n<h3>PHP <code>str_pad()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_pad ( string $input , int $pad_length [, string $pad_string = \" \" [, int $pad_type = STR_PAD_RIGHT ]] ) : string<\/code><\/pre>\n<h3>PHP <code>str_pad()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>input<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>pad_length<\/code> \u2014 If the value of pad_length is negative, less than, or equal to the length of the input string, no padding takes place, and input will be returned. <\/p>\n<\/li>\n<li>\n<p><code>pad_string<\/code> \u2014 Note: The pad_string may be truncated if the required number of padding characters can&#8217;t be evenly divided by the pad_string&#8217;s length. <\/p>\n<\/li>\n<li>\n<p><code>pad_type<\/code> \u2014 Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_pad()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_pad()<\/code> function returns the padded string.<\/p>\n<h3>PHP <code>str_pad()<\/code> Working Examples<\/h3>\n<h4>1. str_pad() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$input = \"Alien\";\necho str_pad($input, 10);                      \/\/ produces \"Alien     \"\necho str_pad($input, 10, \"-=\", STR_PAD_LEFT);  \/\/ produces \"-=-=-Alien\"\necho str_pad($input, 10, \"_\", STR_PAD_BOTH);   \/\/ produces \"__Alien___\"\necho str_pad($input,  6, \"___\");               \/\/ produces \"Alien_\"\necho str_pad($input,  3, \"*\");                 \/\/ produces \"Alien\"\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>str_pad()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <code class=\"parameter\">pad_string<\/code> may be truncated if the required number of padding characters can&#8217;t be evenly divided by the <code class=\"parameter\">pad_string<\/code>&#8216;s length. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Marjune<\/p>\n<pre><code class=\"lang-php\">Since the default pad_type is STR_PAD_RIGHT. using STR_PAD_BOTH were always favor in the right pad if the required number of padding characters can't be evenly divided. \ne.g\n&lt;?php\necho str_pad(\"input\", 10, \"pp\", STR_PAD_BOTH ); \/\/ ppinputppp\necho str_pad(\"input\", 6, \"p\", STR_PAD_BOTH ); \/\/ inputp\necho str_pad(\"input\", 8, \"p\", STR_PAD_BOTH ); \/\/pinputpp\n?&gt;<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">A proper unicode string padder;\n&lt;?php\nmb_internal_encoding('utf-8'); \/\/ @important\nfunction str_pad_unicode($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT) {\n    $str_len = mb_strlen($str);\n    $pad_str_len = mb_strlen($pad_str);\n    if (!$str_len &amp;&amp; ($dir == STR_PAD_RIGHT || $dir == STR_PAD_LEFT)) {\n        $str_len = 1; \/\/ @debug\n    }\n    if (!$pad_len || !$pad_str_len || $pad_len &lt;= $str_len) {\n        return $str;\n    }\n    \n    $result = null;\n    $repeat = ceil($str_len - $pad_str_len + $pad_len);\n    if ($dir == STR_PAD_RIGHT) {\n        $result = $str . str_repeat($pad_str, $repeat);\n        $result = mb_substr($result, 0, $pad_len);\n    } else if ($dir == STR_PAD_LEFT) {\n        $result = str_repeat($pad_str, $repeat) . $str;\n        $result = mb_substr($result, -$pad_len);\n    } else if ($dir == STR_PAD_BOTH) {\n        $length = ($pad_len - $str_len) \/ 2;\n        $repeat = ceil($length \/ $pad_str_len);\n        $result = mb_substr(str_repeat($pad_str, $repeat), 0, floor($length)) \n                    . $str \n                       . mb_substr(str_repeat($pad_str, $repeat), 0, ceil($length));\n    }\n    \n    return $result;\n}\n?&gt;\nTest;\n&lt;?php\n\/\/ needs ie. \"test.php\" file encoded in \"utf-8 without bom\"\n$s = '...';\nfor ($i = 3; $i &lt;= 1000; $i++) {\n    $s1 = str_pad($s, $i, 'AO', STR_PAD_BOTH); \/\/ can not inculde unicode char!!!\n    $s2 = str_pad_unicode($s, $i, '\u00c4\u00d6', STR_PAD_BOTH);\n    $sl1 = strlen($s1);\n    $sl2 = mb_strlen($s2);\n    echo  \"len $sl1: $s1 \\n\";\n    echo  \"len $sl2: $s2 \\n\";\n    echo  \"\\n\";\n    if ($sl1 != $sl2) die(\"Fail!\");\n}\n?&gt;\nOutput;\nlen 3: ... \nlen 3: ... \nlen 4: ...A \nlen 4: ...\u00c4 \nlen 5: A...A \nlen 5: \u00c4...\u00c4 \nlen 6: A...AO \nlen 6: \u00c4...\u00c4\u00d6 \n...<\/code><\/pre>\n<p>Contributed By: wes<\/p>\n<pre><code class=\"lang-php\">Multibyte version:\n&lt;?php\nfunction mb_str_pad($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT, $encoding = NULL)\n{\n    $encoding = $encoding === NULL ? mb_internal_encoding() : $encoding;\n    $padBefore = $dir === STR_PAD_BOTH || $dir === STR_PAD_LEFT;\n    $padAfter = $dir === STR_PAD_BOTH || $dir === STR_PAD_RIGHT;\n    $pad_len -= mb_strlen($str, $encoding);\n    $targetLen = $padBefore &amp;&amp; $padAfter ? $pad_len \/ 2 : $pad_len;\n    $strToRepeatLen = mb_strlen($pad_str, $encoding);\n    $repeatTimes = ceil($targetLen \/ $strToRepeatLen);\n    $repeatedString = str_repeat($pad_str, max(0, $repeatTimes)); \/\/ safe if used with valid utf-8 strings\n    $before = $padBefore ? mb_substr($repeatedString, 0, floor($targetLen), $encoding) : '';\n    $after = $padAfter ? mb_substr($repeatedString, 0, ceil($targetLen), $encoding) : '';\n    return $before . $str . $after;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"str_repeat\">PHP <code>str_repeat()<\/code> Function<\/h2>\n<h3>What does <code>str_repeat()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_repeat()<\/code><\/code> function will give you <code class=\"parameter\">input<\/code> repeated <code class=\"parameter\">multiplier<\/code> times.<\/p>\n<h3>PHP <code>str_repeat()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_repeat ( string $input , int $multiplier ) : string<\/code><\/pre>\n<h3>PHP <code>str_repeat()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>input<\/code> \u2014 The string to be repeated. <\/p>\n<\/li>\n<li>\n<p><code>multiplier<\/code> \u2014 Number of time the input string should be repeated. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_repeat()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_repeat()<\/code> function returns the repeated string.<\/p>\n<h3>PHP <code>str_repeat()<\/code> Working Examples<\/h3>\n<h4>1. str_repeat() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho str_repeat(\"-=\", 10);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">-=-=-=-=-=-=-=-=-=-=<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Damien Bezborodov<\/p>\n<pre><code class=\"lang-php\">Here is a simple one liner to repeat a string multiple times with a separator:\n&lt;?php\nimplode($separator, array_fill(0, $multiplier, $input));\n?&gt;\nExample script:\n&lt;?php\n\/\/ How I like to repeat a string using standard PHP functions\n$input = 'bar';\n$multiplier = 5;\n$separator = ',';\nprint implode($separator, array_fill(0, $multiplier, $input));\nprint \"\\n\";\n\/\/ Say, this comes in handy with count() on an array that we want to use in an\n\/\/ SQL query such as 'WHERE foo IN (...)'\n$args = array('1', '2', '3');\nprint implode(',', array_fill(0, count($args), '?'));\nprint \"\\n\";\n?&gt;\nExample Output:\nbar,bar,bar,bar,bar\n?,?,?<\/code><\/pre>\n<h2 id=\"str_replace\">PHP <code>str_replace()<\/code> Function<\/h2>\n<h3>What does <code>str_replace()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_replace()<\/code><\/code> function will replace all occurrences of the search string with the replacement string.<\/p>\n<h3>PHP <code>str_replace()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) : mixed<\/code><\/pre>\n<h3>PHP <code>str_replace()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>search<\/code> \u2014 The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. <\/p>\n<\/li>\n<li>\n<p><code>replace<\/code> \u2014 The replacement value that replaces found search values. An array may be used to designate multiple replacements. <\/p>\n<\/li>\n<li>\n<p><code>subject<\/code> \u2014 The string or array being searched and replaced on, otherwise known as the haystack. <\/p>\n<\/li>\n<li>\n<p><code>count<\/code> \u2014 If passed, this will be set to the number of replacements performed. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_replace()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_replace()<\/code> function returns a string or an array with the replaced values.<\/p>\n<h3>PHP <code>str_replace()<\/code> Working Examples<\/h3>\n<h4>1. Basic str_replace() examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Provides: &lt;body text='black'&gt;\n$bodytag = str_replace(\"%body%\", \"black\", \"&lt;body text='%body%'&gt;\");\n\/\/ Provides: Hll Wrld f PHP\n$vowels = array(\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\");\n$onlyconsonants = str_replace($vowels, \"\", \"Hello World of PHP\");\n\/\/ Provides: You should eat pizza, beer, and ice cream every day\n$phrase  = \"You should eat fruits, vegetables, and fiber every day.\";\n$healthy = array(\"fruits\", \"vegetables\", \"fiber\");\n$yummy   = array(\"pizza\", \"beer\", \"ice cream\");\n$newphrase = str_replace($healthy, $yummy, $phrase);\n\/\/ Provides: 2\n$str = str_replace(\"ll\", \"\", \"good golly miss molly!\", $count);\necho $count;\n?&gt;<\/code><\/pre>\n<h4>2. Examples of potential str_replace() gotchas<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Order of replacement\n$str     = \"Line 1\\nLine 2\\rLine 3\\r\\nLine 4\\n\";\n$order   = array(\"\\r\\n\", \"\\n\", \"\\r\");\n$replace = '&lt;br \/&gt;';\n\/\/ Processes \\r\\n's first so they aren't converted twice.\n$newstr = str_replace($order, $replace, $str);\n\/\/ Outputs F because A is replaced with B, then B is replaced with C, and so on...\n\/\/ Finally E is replaced with F, because of left to right replacements.\n$search  = array('A', 'B', 'C', 'D', 'E');\n$replace = array('B', 'C', 'D', 'E', 'F');\n$subject = 'A';\necho str_replace($search, $replace, $subject);\n\/\/ Outputs: apearpearle pear\n\/\/ For the same reason mentioned above\n$letters = array('a', 'p');\n$fruit   = array('apple', 'pear');\n$text    = 'a p';\n$output  = str_replace($letters, $fruit, $text);\necho $output;\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>str_replace()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Because <code>str_replace()<\/code> replaces left to right, it might replace a previously inserted value when doing multiple replacements. See also the examples in this document. <\/p>\n<\/li>\n<li>\n<p> This function is case-sensitive. Use <code>str_ireplace()<\/code> for case-insensitive replace. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: nikolaz dot tang<\/p>\n<pre><code class=\"lang-php\">A faster way to replace the strings in multidimensional array is to json_encode() it, do the str_replace() and then json_decode() it, like this: \n \n&lt;?php \nfunction str_replace_json($search, $replace, $subject){ \n     return json_decode(str_replace($search, $replace,  json_encode($subject))); \n \n} \n?&gt; \n \nThis method is almost 3x faster (in 10000 runs.) than using recursive calling and looping method, and 10x simpler in coding. \n \nCompared to: \n \n&lt;?php \nfunction str_replace_deep($search, $replace, $subject) \n{ \n    if (is_array($subject)) \n    { \n        foreach($subject as &amp;$oneSubject) \n            $oneSubject = str_replace_deep($search, $replace, $oneSubject); \n        unset($oneSubject); \n        return $subject; \n    } else { \n        return str_replace($search, $replace, $subject); \n    } \n} \n?&gt;<\/code><\/pre>\n<p>Contributed By: moostende<\/p>\n<pre><code class=\"lang-php\">Note that this does not replace strings that become part of replacement strings. This may be a problem when you want to remove multiple instances of the same repetative pattern, several times in a row. \n \nIf you want to remove all dashes but one from the string '-aaa----b-c-----d--e---f' resulting in '-aaa-b-c-d-e-f', you cannot use str_replace. Instead, use preg_replace: \n \n&lt;?php \n$challenge = '-aaa----b-c-----d--e---f'; \necho str_replace('--', '-', $challenge).'&lt;br&gt;'; \necho preg_replace('\/--+\/', '-', $challenge).'&lt;br&gt;'; \n?&gt; \n \nThis outputs the following: \n-aaa--b-c---d-e--f \n-aaa-b-c-d-e-f<\/code><\/pre>\n<p>Contributed By: Wes Foster<\/p>\n<pre><code class=\"lang-php\">Feel free to optimize this using the while\/for or anything else, but this is a bit of code that allows you to replace strings found in an associative array. \n \nFor example: \n&lt;?php \n$replace = array( \n'dog' =&gt; 'cat', \n'apple' =&gt; 'orange' \n'chevy' =&gt; 'ford' \n); \n \n$string = 'I like to eat an apple with my dog in my chevy'; \n \necho str_replace_assoc($replace,$string); \n \n\/\/ Echo: I like to eat an orange with my cat in my ford \n?&gt; \n \nHere is the function: \n \n&lt;?php \nfunction strReplaceAssoc(array $replace, $subject) { \n   return str_replace(array_keys($replace), array_values($replace), $subject);    \n} \n?&gt; \n \n[Jun 1st, 2010 - EDIT BY thiago AT php DOT net: Function has been replaced with an updated version sent by ljelinek AT gmail DOT com]<\/code><\/pre>\n<p>Contributed By: Alberto Lepe<\/p>\n<pre><code class=\"lang-php\">Be careful when replacing characters (or repeated patterns in the FROM and TO arrays): \n \nFor example: \n \n&lt;?php \n$arrFrom = array(\"1\",\"2\",\"3\",\"B\"); \n$arrTo = array(\"A\",\"B\",\"C\",\"D\"); \n$word = \"ZBB2\"; \necho str_replace($arrFrom, $arrTo, $word); \n?&gt; \n \nI would expect as result: \"ZDDB\" \nHowever, this return: \"ZDDD\" \n(Because B = D according to our array) \n \nTo make this work, use \"strtr\" instead: \n \n&lt;?php \n$arr = array(\"1\" =&gt; \"A\",\"2\" =&gt; \"B\",\"3\" =&gt; \"C\",\"B\" =&gt; \"D\"); \n$word = \"ZBB2\"; \necho strtr($word,$arr); \n?&gt; \n \nThis returns: \"ZDDB\"<\/code><\/pre>\n<p>Contributed By: David Holt<\/p>\n<pre><code class=\"lang-php\">Be aware that if you use this for filtering &amp; sanitizing some form of user input, or remove ALL instances of a string, there's another gotcha to watch out for:\n\/\/ Remove all double characters\n$string=\"1001011010\";\n$string=str_replace(array(\"11\",\"00\"),\"\",$string);\n\/\/ Output: \"110010\"\n$string=\"&lt;ht&lt;html&gt;ml&gt; Malicious code &lt;\/&lt;html&gt;html&gt; etc\";\n$string=str_replace(array(\"&lt;html&gt;\",\"&lt;\/html&gt;\"),\"\",$string);\n\/\/ Output: \"&lt;html&gt; Malicious code &lt;\/html&gt; etc\"<\/code><\/pre>\n<p>Contributed By: jay_knows_(all)uk<\/p>\n<pre><code class=\"lang-php\">This strips out horrible MS word characters. \nJust keep fine tuning it until you get what you need, you'll see ive commented some out which caused problems for me.\nThere could be some that need adding in, but its a start to anyone who wishes to make their own custom function.\n&lt;?php\nfunction msword_conversion($str) \n{ \n$str = str_replace(chr(130), ',', $str);    \/\/ baseline single quote\n$str = str_replace(chr(131), 'NLG', $str);  \/\/ florin\n$str = str_replace(chr(132), '\"', $str);    \/\/ baseline double quote\n$str = str_replace(chr(133), '...', $str);  \/\/ ellipsis\n$str = str_replace(chr(134), '**', $str);   \/\/ dagger (a second footnote)\n$str = str_replace(chr(135), '***', $str);  \/\/ double dagger (a third footnote)\n$str = str_replace(chr(136), '^', $str);    \/\/ circumflex accent\n$str = str_replace(chr(137), 'o\/oo', $str); \/\/ permile\n$str = str_replace(chr(138), 'Sh', $str);   \/\/ S Hacek\n$str = str_replace(chr(139), '&lt;', $str);    \/\/ left single guillemet\n\/\/ $str = str_replace(chr(140), 'OE', $str);   \/\/ OE ligature\n$str = str_replace(chr(145), \"'\", $str);    \/\/ left single quote\n$str = str_replace(chr(146), \"'\", $str);    \/\/ right single quote\n\/\/ $str = str_replace(chr(147), '\"', $str);    \/\/ left double quote\n\/\/ $str = str_replace(chr(148), '\"', $str);    \/\/ right double quote\n$str = str_replace(chr(149), '-', $str);    \/\/ bullet\n$str = str_replace(chr(150), '-\u2013', $str);    \/\/ endash\n$str = str_replace(chr(151), '--', $str);   \/\/ emdash\n\/\/ $str = str_replace(chr(152), '~', $str);    \/\/ tilde accent\n\/\/ $str = str_replace(chr(153), '(TM)', $str); \/\/ trademark ligature\n$str = str_replace(chr(154), 'sh', $str);   \/\/ s Hacek\n$str = str_replace(chr(155), '&gt;', $str);    \/\/ right single guillemet\n\/\/ $str = str_replace(chr(156), 'oe', $str);   \/\/ oe ligature\n$str = str_replace(chr(159), 'Y', $str);    \/\/ Y Dieresis\n$str = str_replace('\u00b0C', '&amp;deg;C', $str);    \/\/ Celcius is used quite a lot so it makes sense to add this in\n$str = str_replace('\u00a3', '&amp;pound;', $str); \n$str = str_replace(\"'\", \"'\", $str);\n$str = str_replace('\"', '\"', $str);\n$str = str_replace('\u2013', '&amp;ndash;', $str);\nreturn $str;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"str_rot13\">PHP <code>str_rot13()<\/code> Function<\/h2>\n<h3>What does <code>str_rot13()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_rot13()<\/code><\/code> function will give you the resulting string.<\/p>\n<h3>PHP <code>str_rot13()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_rot13 ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>str_rot13()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_rot13()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_rot13()<\/code> function returns the ROT13 version of the given string.<\/p>\n<h3>PHP <code>str_rot13()<\/code> Working Examples<\/h3>\n<h4>1. str_rot13() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho str_rot13('PHP 4.3.0'); \/\/ CUC 4.3.0\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: shaun<\/p>\n<pre><code class=\"lang-php\">I was reminded again of the desire for a generic str_rot function. Character manipulation loops in PHP are slow compared to their C counterparts, so here's a tuned version of the previous function I posted. It's 1.6 times as fast, mainly by avoiding chr() calls.\n&lt;?php\nfunction str_rot($s, $n = 13) {\n    static $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n    $n = (int)$n % 26;\n    if (!$n) return $s;\n    if ($n == 13) return str_rot13($s);\n    for ($i = 0, $l = strlen($s); $i &lt; $l; $i++) {\n        $c = $s[$i];\n        if ($c &gt;= 'a' &amp;&amp; $c &lt;= 'z') {\n            $s[$i] = $letters[(ord($c) - 71 + $n) % 26];\n        } else if ($c &gt;= 'A' &amp;&amp; $c &lt;= 'Z') {\n            $s[$i] = $letters[(ord($c) - 39 + $n) % 26 + 26];\n        }\n    }\n    return $s;\n}\n?&gt;\nBut using strtr() you can get something 10 times as fast as the above :\n&lt;?php\nfunction str_rot($s, $n = 13) {\n    static $letters = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';\n    $n = (int)$n % 26;\n    if (!$n) return $s;\n    if ($n &lt; 0) $n += 26;\n    if ($n == 13) return str_rot13($s);\n    $rep = substr($letters, $n * 2) . substr($letters, 0, $n * 2);\n    return strtr($s, $letters, $rep);\n}\n?&gt;\nThis technique is faster because PHP's strtr is implemented in C using a byte lookup table (it has O(m + n) complexity). However, PHP 6 will use Unicode, so I guess(?) strtr will then have to be implemented with a search for each character (O(m * n)). Using strtr might still be faster since it offloads the character manipulation to C rather than PHP, but I don't really know. Take your pick.\nHappy coding!\n(Benchmark code):\n&lt;?php\nfor ($k = 0; $k &lt; 10; $k++) {\n    $s = 'The quick brown fox jumps over the lazy dog.';\n    $t = microtime(1);\n    for ($i = 0; $i &lt; 1000; $i++) $s = str_rot($s, $i);\n    $t = microtime(1) - $t;\n    echo number_format($t, 3) . \"\\n\";\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"str_shuffle\">PHP <code>str_shuffle()<\/code> Function<\/h2>\n<h3>What does <code>str_shuffle()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_shuffle()<\/code><\/code> function will <code>str_shuffle()<\/code> shuffles a string. One permutation of all possible is created.<\/p>\n<h3>PHP <code>str_shuffle()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_shuffle ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>str_shuffle()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_shuffle()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_shuffle()<\/code> function returns the shuffled string.<\/p>\n<h3>PHP <code>str_shuffle()<\/code> Working Examples<\/h3>\n<h4>1. str_shuffle() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = 'abcdef';\n$shuffled = str_shuffle($str);\n\/\/ This will echo something like: bfdaec\necho $shuffled;\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP str_shuffle()<\/code> Function<\/h3>\n<p><strong>7.1.0 \u2014 <\/strong> The internal randomization algorithm has been changed to use the \u00bb Mersenne Twister Random Number Generator instead of the libc rand function. <\/p>\n<h3>Important Points about PHP <code>str_shuffle()<\/code> Function<\/h3>\n<ol>\n<li>\n<p>This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a cryptographically secure value, consider using <code>random_int()<\/code>, <code>random_bytes()<\/code>, or <code>openssl_random_pseudo_bytes()<\/code> instead.<\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jojersztajner<\/p>\n<pre><code class=\"lang-php\">Aoccdrnig to rseearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is that the frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe.\nHree's a cdoe taht slerbmcas txet in tihs way:\n&lt;?php\n    function scramble_word($word) {\n        if (strlen($word) &lt; 2)\n            return $word;\n        else\n            return $word{0} . str_shuffle(substr($word, 1, -1)) . $word{strlen($word) - 1};\n    }\n    echo preg_replace('\/(\\w+)\/e', 'scramble_word(\"\\1\")', 'A quick brown fox jumped over the lazy dog.');\n?&gt;\nIt may be ufseul if you wnat to cetare an aessblicce CTCPAHA.<\/code><\/pre>\n<p>Contributed By: blamoo2<\/p>\n<pre><code class=\"lang-php\">This function is affected by srand():\n&lt;?php\nsrand(12345);\necho str_shuffle('Randomize me') . '&lt;br\/&gt;'; \/\/ \"demmiezr aon\"\necho str_shuffle('Randomize me') . '&lt;br\/&gt;'; \/\/ \"izadmeo rmen\"\nsrand(12345);\necho str_shuffle('Randomize me') . '&lt;br\/&gt;'; \/\/ \"demmiezr aon\" again\n?&gt;<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">A proper unicode string shuffle;\n&lt;?php\nfunction str_shuffle_unicode($str) {\n    $tmp = preg_split(\"\/\/u\", $str, -1, PREG_SPLIT_NO_EMPTY);\n    shuffle($tmp);\n    return join(\"\", $tmp);\n}\n?&gt;\n$str = \"\u015eeker y\u00e2rim\"; \/\/ My sweet love\necho str_shuffle($str); \/\/ i\ufffdeymr\u0162ekr \ufffd\necho str_shuffle_unicode($str); \/\/ \u015er mreyeik\u00e2<\/code><\/pre>\n<h2 id=\"str_split\">PHP <code>str_split()<\/code> Function<\/h2>\n<h3>What does <code>str_split()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_split()<\/code><\/code> function will converts a string to an array.<\/p>\n<h3>PHP <code>str_split()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_split ( string $string [, int $split_length = 1 ] ) : array<\/code><\/pre>\n<h3>PHP <code>str_split()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>split_length<\/code> \u2014 Maximum length of the chunk. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_split()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_split()<\/code> function returns d array will be broken down into chunks with each being <code class=\"parameter\">split_length<\/code> in length, otherwise each chunk will be one character in length.<\/p>\n<h3>PHP <code>str_split()<\/code> Working Examples<\/h3>\n<h4>1. Example uses of str_split()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Hello Friend\";\n$arr1 = str_split($str);\n$arr2 = str_split($str, 3);\nprint_r($arr1);\nprint_r($arr2);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Array\n(\n [0] =&gt; H\n [1] =&gt; e\n [2] =&gt; l\n [3] =&gt; l\n [4] =&gt; o\n [5] =&gt;\n [6] =&gt; F\n [7] =&gt; r\n [8] =&gt; i\n [9] =&gt; e\n [10] =&gt; n\n [11] =&gt; d\n)\nArray\n(\n [0] =&gt; Hel\n [1] =&gt; lo\n [2] =&gt; Fri\n [3] =&gt; end\n)<\/code><\/pre>\n<h3>Important Points about PHP <code>str_split()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> <code>str_split()<\/code> will split into bytes, rather than characters when dealing with a multi-byte encoded string. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">A proper unicode string split;\n&lt;?php\nfunction str_split_unicode($str, $l = 0) {\n    if ($l &gt; 0) {\n        $ret = array();\n        $len = mb_strlen($str, \"UTF-8\");\n        for ($i = 0; $i &lt; $len; $i += $l) {\n            $ret[] = mb_substr($str, $i, $l, \"UTF-8\");\n        }\n        return $ret;\n    }\n    return preg_split(\"\/\/u\", $str, -1, PREG_SPLIT_NO_EMPTY);\n}\n?&gt;\n$s = \"Il\u0131k s\u00fct\"; \/\/ Mild milk\nprint_r(str_split($s, 3));\nprint_r(str_split_unicode($s, 3));\nArray\n(\n    [0] =&gt; Il\ufffd\n    [1] =&gt; \ufffdk \n    [2] =&gt; s\u00fc\n    [3] =&gt; t\n)\nArray\n(\n    [0] =&gt; Il\u0131\n    [1] =&gt; k s\n    [2] =&gt; \u00fct\n)<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">A new version of \"str_split_unicode\" prev.\n&lt;?php\nfunction str_split_unicode($str, $length = 1) {\n    $tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);\n    if ($length &gt; 1) {\n        $chunks = array_chunk($tmp, $length);\n        foreach ($chunks as $i =&gt; $chunk) {\n            $chunks[$i] = join('', (array) $chunk);\n        }\n        $tmp = $chunks;\n    }\n    return $tmp;\n}\n?&gt;\n$s = '\u00d6zg\u00fcr Yaz\u0131l\u0131m!'; \/\/ Open Source!\nprint_r(str_split_unicode($s));\nprint_r(str_split_unicode($s, 3));\nArray\n(\n    [0] =&gt; \u00d6\n    [1] =&gt; z\n    [2] =&gt; g\n    [3] =&gt; \u00fc\n    [4] =&gt; r\n    [5] =&gt;  \n    [6] =&gt; Y\n    [7] =&gt; a\n    [8] =&gt; z\n    [9] =&gt; \u0131\n    [10] =&gt; l\n    [11] =&gt; \u0131\n    [12] =&gt; m\n    [13] =&gt; !\n)\nArray\n(\n    [0] =&gt; \u00d6zg\n    [1] =&gt; \u00fcr \n    [2] =&gt; Yaz\n    [3] =&gt; \u0131l\u0131\n    [4] =&gt; m!\n)<\/code><\/pre>\n<h2 id=\"str_word_count\">PHP <code>str_word_count()<\/code> Function<\/h2>\n<h3>What does <code>str_word_count()<\/code> do?<\/h3>\n<p>The PHP <code><code>str_word_count()<\/code><\/code> function will give you <\/p>\n<h3>PHP <code>str_word_count()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) : mixed<\/code><\/pre>\n<h3>PHP <code>str_word_count()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The string <\/p>\n<\/li>\n<li>\n<p><code>format<\/code> \u2014 Specify the return value of this function. The current supported values are: <\/p>\n<\/li>\n<li>\n<p><code>charlist<\/code> \u2014 A list of additional characters which will be considered as &#8216;word&#8217; <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>str_word_count()<\/code> Return Value<\/h3>\n<p>The PHP <code>str_word_count()<\/code> function returns an array or an integer, depending on the <code class=\"parameter\">format<\/code> chosen.<\/p>\n<h3>PHP <code>str_word_count()<\/code> Working Examples<\/h3>\n<h4>1. A str_word_count() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Hello fri3nd, you're\n       looking          good today!\";\nprint_r(str_word_count($str, 1));\nprint_r(str_word_count($str, 2));\nprint_r(str_word_count($str, 1, '\u00e0\u00e1\u00e3\u00e73'));\necho str_word_count($str);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Array\n(\n [0] =&gt; Hello\n [1] =&gt; fri\n [2] =&gt; nd\n [3] =&gt; you're\n [4] =&gt; looking\n [5] =&gt; good\n [6] =&gt; today\n)\nArray\n(\n [0] =&gt; Hello\n [6] =&gt; fri\n [10] =&gt; nd\n [14] =&gt; you're\n [29] =&gt; looking\n [46] =&gt; good\n [51] =&gt; today\n)\nArray\n(\n [0] =&gt; Hello\n [1] =&gt; fri3nd\n [2] =&gt; you're\n [3] =&gt; looking\n [4] =&gt; good\n [5] =&gt; today\n)\n7<\/code><\/pre>\n<h3>Changelog for PHP str_word_count()<\/code> Function<\/h3>\n<p><strong>5.1.0 \u2014 <\/strong> Added the <code class=\"parameter\">charlist<\/code> parameter <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: cito<\/p>\n<pre><code class=\"lang-php\">&lt;?php\n\/***\n * This simple utf-8 word count function (it only counts) \n * is a bit faster then the one with preg_match_all\n * about 10x slower then the built-in str_word_count\n * \n * If you need the hyphen or other code points as word-characters\n * just put them into the [brackets] like [^\\p{L}\\p{N}\\'\\-]\n * If the pattern contains utf-8, utf8_encode() the pattern,\n * as it is expected to be valid utf-8 (using the u modifier).\n **\/\n\/\/ Jonny 5's simple word splitter\nfunction str_word_count_utf8($str) {\n  return count(preg_split('~[^\\p{L}\\p{N}\\']+~u',$str));\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: splogamurugan<\/p>\n<pre><code class=\"lang-php\">We can also specify a range of values for charlist. \n \n&lt;?php \n$str = \"Hello fri3nd, you're \n       looking          good today! \n       look1234ing\"; \nprint_r(str_word_count($str, 1, '0..3')); \n?&gt; \n \nwill give the result as \n \nArray ( [0] =&gt; Hello [1] =&gt; fri3nd [2] =&gt; you're [3] =&gt; looking [4] =&gt; good [5] =&gt; today [6] =&gt; look123 [7] =&gt; ing )<\/code><\/pre>\n<h2 id=\"strcasecmp\">PHP <code>strcasecmp()<\/code> Function<\/h2>\n<h3>What does <code>strcasecmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strcasecmp()<\/code><\/code> function will binary safe case-insensitive string comparison.<\/p>\n<h3>PHP <code>strcasecmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strcasecmp ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<h3>PHP <code>strcasecmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strcasecmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strcasecmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h3>PHP <code>strcasecmp()<\/code> Working Examples<\/h3>\n<h4>1. strcasecmp() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$var1 = \"Hello\";\n$var2 = \"hello\";\nif (strcasecmp($var1, $var2) == 0) {\n    echo '$var1 is equal to $var2 in a case-insensitive string comparison';\n}\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: chris<\/p>\n<pre><code class=\"lang-php\">A simple multibyte-safe case-insensitive string comparison:\n&lt;?php\nfunction mb_strcasecmp($str1, $str2, $encoding = null) {\n    if (null === $encoding) { $encoding = mb_internal_encoding(); }\n    return strcmp(mb_strtoupper($str1, $encoding), mb_strtoupper($str2, $encoding));\n}\n?&gt;\nCaveat: watch out for edge cases like \"\u00df\".<\/code><\/pre>\n<p>Contributed By: Anonymous<\/p>\n<pre><code class=\"lang-php\">The sample above is only true on some platforms that only use a simple 'C' locale, where individual bytes are considered as complete characters that are converted to lowercase before being differentiated.\nOther locales (see LC_COLLATE and LC_ALL) use the difference of collation order of characters, where characters may be groups of bytes taken from the input strings, or simply return -1, 0, or 1 as the collation order is not simply defined by comparing individual characters but by more complex rules.\nDon't base your code on a specific non null value returned by strcmp() or strcasecmp(): it is not portable. Just consider the sign of the result and be sure to use the correct locale!<\/code><\/pre>\n<h2 id=\"strchr\">PHP <code>strchr()<\/code> Function<\/h2>\n<h3>What does <code>strchr()<\/code> do?<\/h3>\n<p>The PHP <code><code>strchr()<\/code><\/code> function will this function is an alias of: <code>strstr()<\/code>.<\/p>\n<h3>PHP <code>strchr()<\/code> Syntax<\/h3>\n<h3>PHP <code>strchr()<\/code> Parameters<\/h3>\n<ol><\/ol>\n<p>This function does not accept any parameters.<\/p>\n<h2 id=\"strcmp\">PHP <code>strcmp()<\/code> Function<\/h2>\n<h3>What does <code>strcmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strcmp()<\/code><\/code> function will note that this comparison is case sensitive.<\/p>\n<h3>PHP <code>strcmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strcmp ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<h3>PHP <code>strcmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strcmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strcmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h3>PHP <code>strcmp()<\/code> Working Examples<\/h3>\n<h4>1. strcmp() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$var1 = \"Hello\";\n$var2 = \"hello\";\nif (strcmp($var1, $var2) !== 0) {\n    echo '$var1 is not equal to $var2 in a case sensitive string comparison';\n}\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jendoj<\/p>\n<pre><code class=\"lang-php\">If you rely on strcmp for safe string comparisons, both parameters must be strings, the result is otherwise extremely unpredictable.\nFor instance you may get an unexpected 0, or return values of NULL, -2, 2, 3 and -3.\nstrcmp(\"5\", 5) =&gt; 0\nstrcmp(\"15\", 0xf) =&gt; 0\nstrcmp(61529519452809720693702583126814, 61529519452809720000000000000000) =&gt; 0\nstrcmp(NULL, false) =&gt; 0\nstrcmp(NULL, \"\") =&gt; 0\nstrcmp(NULL, 0) =&gt; -1\nstrcmp(false, -1) =&gt; -2\nstrcmp(\"15\", NULL) =&gt; 2\nstrcmp(NULL, \"foo\") =&gt; -3\nstrcmp(\"foo\", NULL) =&gt; 3\nstrcmp(\"foo\", false) =&gt; 3\nstrcmp(\"foo\", 0) =&gt; 1\nstrcmp(\"foo\", 5) =&gt; 1\nstrcmp(\"foo\", array()) =&gt; NULL + PHP Warning\nstrcmp(\"foo\", new stdClass) =&gt; NULL + PHP Warning\nstrcmp(function(){}, \"\") =&gt; NULL + PHP Warning<\/code><\/pre>\n<p>Contributed By: lehal2<\/p>\n<pre><code class=\"lang-php\">I hope this will give you a clear idea how strcmp works internally. \n \n&lt;?php \n$str1 = \"b\"; \necho ord($str1); \/\/98 \necho \"&lt;br\/&gt;\"; \n$str2 = \"t\"; \necho ord($str2); \/\/116 \necho \"&lt;br\/&gt;\"; \necho ord($str1)-ord($str2);\/\/-18 \n$str1 = \"bear\"; \n$str2 = \"tear\"; \n$str3 = \"\"; \necho \"&lt;pre&gt;\"; \necho strcmp($str1, $str2); \/\/ -18 \necho \"&lt;br\/&gt;\"; \necho strcmp($str2, $str1); \/\/18 \necho \"&lt;br\/&gt;\"; \necho strcmp($str2, $str2); \/\/0 \necho \"&lt;br\/&gt;\"; \necho strcmp($str2, $str3); \/\/4 \necho \"&lt;br\/&gt;\"; \necho strcmp($str3, $str2); \/\/-4 \necho \"&lt;br\/&gt;\"; \necho strcmp($str3, $str3); \/\/ 0 \necho \"&lt;\/pre&gt;\"; \n?&gt;<\/code><\/pre>\n<p>Contributed By: Rob Wiesler<\/p>\n<pre><code class=\"lang-php\">One big caveat - strings retrieved from the backtick operation may be zero terminated (C-style), and therefore will not be equal to the non-zero terminated strings (roughly Pascal-style) normal in PHP. The workaround is to surround every `` pair or shell_exec() function with the trim() function. This is likely to be an issue with other functions that invoke shells; I haven't bothered to check.\nOn Debian Lenny (and RHEL 5, with minor differences), I get this:\n====PHP====\n&lt;?php\n$sz = `pwd`;\n$ps = \"\/var\/www\";\necho \"Zero-terminated string:&lt;br \/&gt;sz = \".$sz.\"&lt;br \/&gt;str_split(sz) = \"; print_r(str_split($sz));\necho \"&lt;br \/&gt;&lt;br \/&gt;\";\necho \"Pascal-style string:&lt;br \/&gt;ps = \".$ps.\"&lt;br \/&gt;str_split(ps) = \"; print_r(str_split($ps));\necho \"&lt;br \/&gt;&lt;br \/&gt;\";\necho \"Normal results of comparison:&lt;br \/&gt;\";\necho \"sz == ps = \".($sz == $ps ? \"true\" : \"false\").\"&lt;br \/&gt;\";\necho \"strcmp(sz,ps) = \".strcmp($sz,$ps);\necho \"&lt;br \/&gt;&lt;br \/&gt;\";\necho \"Comparison with trim()'d zero-terminated string:&lt;br \/&gt;\";\necho \"trim(sz) = \".trim($sz).\"&lt;br \/&gt;\";\necho \"str_split(trim(sz)) = \"; print_r(str_split(trim($sz))); echo \"&lt;br \/&gt;\";\necho \"trim(sz) == ps = \".(trim($sz) == $ps ? \"true\" : \"false\").\"&lt;br \/&gt;\";\necho \"strcmp(trim(sz),ps) = \".strcmp(trim($sz),$ps);\n?&gt;\n====Output====\nZero-terminated string:\nsz = \/var\/www \nstr_split(sz) = Array ( [0] =&gt; \/ [1] =&gt; v [2] =&gt; a [3] =&gt; r [4] =&gt; \/ [5] =&gt; w [6] =&gt; w [7] =&gt; w [8] =&gt; ) \nPascal-style string:\nps = \/var\/www\nstr_split(ps) = Array ( [0] =&gt; \/ [1] =&gt; v [2] =&gt; a [3] =&gt; r [4] =&gt; \/ [5] =&gt; w [6] =&gt; w [7] =&gt; w ) \nNormal results of comparison:\nsz == ps = false\nstrcmp(sz,ps) = 1\nComparison with trim()'d zero-terminated string:\ntrim(sz) = \/var\/www\nstr_split(trim(sz)) = Array ( [0] =&gt; \/ [1] =&gt; v [2] =&gt; a [3] =&gt; r [4] =&gt; \/ [5] =&gt; w [6] =&gt; w [7] =&gt; w ) \ntrim(sz) == ps = true\nstrcmp(trim(sz),ps) = 0<\/code><\/pre>\n<p>Contributed By: frewuill<\/p>\n<pre><code class=\"lang-php\">Hey be sure the string you are comparing has not special characters like '\\n' or something like that.<\/code><\/pre>\n<h2 id=\"strcoll\">PHP <code>strcoll()<\/code> Function<\/h2>\n<h3>What does <code>strcoll()<\/code> do?<\/h3>\n<p>The PHP <code><code>strcoll()<\/code><\/code> function will note that this comparison is case sensitive, and unlike <code>strcmp()<\/code> this function is not binary safe.<\/p>\n<h3>PHP <code>strcoll()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strcoll ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<h3>PHP <code>strcoll()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strcoll()<\/code> Return Value<\/h3>\n<p>The PHP <code>strcoll()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h2 id=\"strcspn\">PHP <code>strcspn()<\/code> Function<\/h2>\n<h3>What does <code>strcspn()<\/code> do?<\/h3>\n<p>The PHP <code><code>strcspn()<\/code><\/code> function will find length of initial segment not matching mask.<\/p>\n<h3>PHP <code>strcspn()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strcspn ( string $subject , string $mask [, int $start [, int $length ]] ) : int<\/code><\/pre>\n<h3>PHP <code>strcspn()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>subject<\/code> \u2014 The string to examine. <\/p>\n<\/li>\n<li>\n<p><code>mask<\/code> \u2014 The string containing every disallowed character. <\/p>\n<\/li>\n<li>\n<p><code>start<\/code> \u2014 The position in subject to start searching. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 The length of the segment from subject to examine. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strcspn()<\/code> Return Value<\/h3>\n<p>The PHP <code>strcspn()<\/code> function returns the length of the initial segment of <code class=\"parameter\">subject<\/code> which consists entirely of characters <strong>not<\/strong> in <code class=\"parameter\">mask<\/code>.<\/p>\n<h3>PHP <code>strcspn()<\/code> Working Examples<\/h3>\n<h4>1. strcspn() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$a = strcspn('abcd',  'apple');\n$b = strcspn('abcd',  'banana');\n$c = strcspn('hello', 'l');\n$d = strcspn('hello', 'world');\n$e = strcspn('abcdhelloabcd', 'abcd', -9);\n$f = strcspn('abcdhelloabcd', 'abcd', -9, -5);\nvar_dump($a);\nvar_dump($b);\nvar_dump($c);\nvar_dump($d);\nvar_dump($e);\nvar_dump($f);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">int(0)\nint(0)\nint(2)\nint(2)\nint(5)\nint(4)<\/code><\/pre>\n<h3>Important Points about PHP <code>strcspn()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> When a <code class=\"parameter\">start<\/code> parameter is set, the returned length is counted starting from this position, not from the beginning of <code class=\"parameter\">subject<\/code>. <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"strip_tags\">PHP <code>strip_tags()<\/code> Function<\/h2>\n<h3>What does <code>strip_tags()<\/code> do?<\/h3>\n<p>The PHP <code><code>strip_tags()<\/code><\/code> function will give you a string with all NULL bytes, HTML and PHP tags stripped from a given <code class=\"parameter\">str<\/code>. It uses the same tag stripping state machine as the <code>fgetss()<\/code> function.<\/p>\n<h3>PHP <code>strip_tags()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strip_tags ( string $str [, string $allowable_tags ] ) : string<\/code><\/pre>\n<h3>PHP <code>strip_tags()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>allowable_tags<\/code> \u2014 You can use the optional second parameter to specify tags which should not be stripped. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strip_tags()<\/code> Return Value<\/h3>\n<p>The PHP <code>strip_tags()<\/code> function returns the stripped string.<\/p>\n<h3>PHP <code>strip_tags()<\/code> Working Examples<\/h3>\n<h4>1. strip_tags() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = '&lt;p&gt;Test paragraph.&lt;\/p&gt;&lt;!-- Comment --&gt; &lt;a href=\"#fragment\"&gt;Other text&lt;\/a&gt;';\necho strip_tags($text);\necho \"\\n\";\n\/\/ Allow &lt;p&gt; and &lt;a&gt;\necho strip_tags($text, '&lt;p&gt;&lt;a&gt;');\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Test paragraph. Other text\n&lt;p&gt;Test paragraph.&lt;\/p&gt; &lt;a href=\"#fragment\"&gt;Other text&lt;\/a&gt;<\/code><\/pre>\n<h3>Changelog for PHP strip_tags()<\/code> Function<\/h3>\n<p><strong>5.3.4 \u2014 <\/strong> <code>strip_tags()<\/code> ignores self-closing XHTML tags in <code class=\"parameter\">allowable_tags<\/code>. <\/p>\n<h3>Important Points about PHP <code>strip_tags()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with <code class=\"parameter\">allowable_tags<\/code>. <\/p>\n<\/li>\n<li>\n<p> In PHP 5.3.4 and later, self-closing XHTML tags are ignored and only non-self-closing tags should be used in <code class=\"parameter\">allowable_tags<\/code>. For example, to allow both <strong>&lt;br&gt;<\/strong> and <strong>&lt;br\/&gt;<\/strong>, you should use: <\/p>\n<\/li>\n<pre><code class=\"lang-php\">&lt;?php\nstrip_tags($input, '&lt;br&gt;');\n?&gt;<\/code><\/pre>\n<\/li>\n<li>\n<p> This function should not be used to try to prevent XSS attacks. Use more appropiate functions like <code>htmlspecialchars()<\/code> or other means depending on the context of the output. <\/p>\n<\/li>\n<li>\n<p> Because <code>strip_tags()<\/code> does not actually validate the HTML, partial or broken tags can result in the removal of more text\/data than expected. <\/p>\n<\/li>\n<li>\n<p> This function does not modify any attributes on the tags that you allow using <code class=\"parameter\">allowable_tags<\/code>, including the <strong>style<\/strong> and <strong>onmouseover<\/strong> attributes that a mischievous user may abuse when posting text that will be shown to other users. <\/p>\n<\/li>\n<li>\n<p> Tag names within the input HTML that are greater than 1023 bytes in length will be treated as though they are invalid, regardless of the <code class=\"parameter\">allowable_tags<\/code> parameter. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: mariusz.tarnaski<\/p>\n<pre><code class=\"lang-php\">Hi. I made a function that removes the HTML tags along with their contents: \n \nFunction: \n&lt;?php \nfunction strip_tags_content($text, $tags = '', $invert = FALSE) { \n \n  preg_match_all('\/&lt;(.+?)[\\s]*\\\/?[\\s]*&gt;\/si', trim($tags), $tags); \n  $tags = array_unique($tags[1]); \n    \n  if(is_array($tags) AND count($tags) &gt; 0) { \n    if($invert == FALSE) { \n      return preg_replace('@&lt;(?!(?:'. implode('|', $tags) .')\\b)(\\w+)\\b.*?&gt;.*?&lt;\/\\1&gt;@si', '', $text); \n    } \n    else { \n      return preg_replace('@&lt;('. implode('|', $tags) .')\\b.*?&gt;.*?&lt;\/\\1&gt;@si', '', $text); \n    } \n  } \n  elseif($invert == FALSE) { \n    return preg_replace('@&lt;(\\w+)\\b.*?&gt;.*?&lt;\/\\1&gt;@si', '', $text); \n  } \n  return $text; \n} \n?&gt; \n \nSample text: \n$text = '&lt;b&gt;sample&lt;\/b&gt; text with &lt;div&gt;tags&lt;\/div&gt;'; \n \nResult for strip_tags($text): \nsample text with tags \n \nResult for strip_tags_content($text): \n text with \n \nResult for strip_tags_content($text, '&lt;b&gt;'): \n&lt;b&gt;sample&lt;\/b&gt; text with \n \nResult for strip_tags_content($text, '&lt;b&gt;', TRUE); \n text with &lt;div&gt;tags&lt;\/div&gt; \n \nI hope that someone is useful :)<\/code><\/pre>\n<p>Contributed By: doug<\/p>\n<pre><code class=\"lang-php\">\"5.3.4    strip_tags() no longer strips self-closing XHTML tags unless the self-closing XHTML tag is also given in allowable_tags.\"\nThis is poorly worded.\nThe above seems to be saying that, since 5.3.4, if you don't specify \"&lt;br\/&gt;\" in allowable_tags then \"&lt;br\/&gt;\" will not be stripped... but that's not actually what they're trying to say.\nWhat it means is, in versions prior to 5.3.4, it \"strips self-closing XHTML tags unless the self-closing XHTML tag is also given in allowable_tags\", and that since 5.3.4 this is no longer the case.\nSo what reads as \"no longer strips self-closing tags (unless the self-closing XHTML tag is also given in allowable_tags)\" is actually saying \"no longer (strips self-closing tags unless the self-closing XHTML tag is also given in allowable_tags)\".\ni.e.\npre-5.3.4: strip_tags('Hello World&lt;br&gt;&lt;br\/&gt;','&lt;br&gt;') =&gt; 'Hello World&lt;br&gt;' \/\/ strips &lt;br\/&gt; because it wasn't explicitly specified in allowable_tags\n5.3.4 and later: strip_tags('Hello World&lt;br&gt;&lt;br\/&gt;','&lt;br&gt;') =&gt; 'Hello World&lt;br&gt;&lt;br\/&gt;' \/\/ does not strip &lt;br\/&gt; because PHP matches it with &lt;br&gt; in allowable_tags<\/code><\/pre>\n<p>Contributed By: stever<\/p>\n<pre><code class=\"lang-php\">Since strip_tags does not remove attributes and thus creates a potential XSS security hole, here is a small function I wrote to allow only specific tags with specific attributes and strip all other tags and attributes.\nIf you only allow formatting tags such as b, i, and p, and styling attributes such as class, id and style, this will strip all javascript including event triggers in formatting tags.\nNote that allowing anchor tags or href attributes opens another potential security hole that this solution won't protect against. You'll need more comprehensive protection if you plan to allow links in your text.\n&lt;?php\nfunction stripUnwantedTagsAndAttrs($html_str){\n  $xml = new DOMDocument();\n\/\/Suppress warnings: proper error handling is beyond scope of example\n  libxml_use_internal_errors(true);\n\/\/List the tags you want to allow here, NOTE you MUST allow html and body otherwise entire string will be cleared\n  $allowed_tags = array(\"html\", \"body\", \"b\", \"br\", \"em\", \"hr\", \"i\", \"li\", \"ol\", \"p\", \"s\", \"span\", \"table\", \"tr\", \"td\", \"u\", \"ul\");\n\/\/List the attributes you want to allow here\n  $allowed_attrs = array (\"class\", \"id\", \"style\");\n  if (!strlen($html_str)){return false;}\n  if ($xml-&gt;loadHTML($html_str, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)){\n    foreach ($xml-&gt;getElementsByTagName(\"*\") as $tag){\n      if (!in_array($tag-&gt;tagName, $allowed_tags)){\n        $tag-&gt;parentNode-&gt;removeChild($tag);\n      }else{\n        foreach ($tag-&gt;attributes as $attr){\n          if (!in_array($attr-&gt;nodeName, $allowed_attrs)){\n            $tag-&gt;removeAttribute($attr-&gt;nodeName);\n          }\n        }\n      }\n    }\n  }\n  return $xml-&gt;saveHTML();\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: bzplan<\/p>\n<pre><code class=\"lang-php\">A HTML code like this: \n&lt;?php\n$html = '\n&lt;div&gt;\n&lt;p style=\"color:blue;\"&gt;color is blue&lt;\/p&gt;&lt;p&gt;size is &lt;span style=\"font-size:200%;\"&gt;huge&lt;\/span&gt;&lt;\/p&gt;\n&lt;p&gt;material is wood&lt;\/p&gt;\n&lt;\/div&gt;\n'; \n?&gt;\nwith &lt;?php $str = strip_tags($html); ?&gt;\n... the result is:\n$str = 'color is bluesize is huge\nmaterial is wood'; \nnotice: the words 'blue' and 'size' grow together :( \nand line-breaks are still in new string $str\nif you need a space between the words (and without line-break) \nuse my function: &lt;?php $str = rip_tags($html); ?&gt;\n... the result is:\n$str = 'color is blue size is huge material is wood'; \nthe function: \n&lt;?php\n\/\/ -------------------------------------------------------------- \nfunction rip_tags($string) { \n    \n    \/\/ ----- remove HTML TAGs ----- \n    $string = preg_replace ('\/&lt;[^&gt;]*&gt;\/', ' ', $string); \n    \n    \/\/ ----- remove control characters ----- \n    $string = str_replace(\"\\r\", '', $string);    \/\/ --- replace with empty space\n    $string = str_replace(\"\\n\", ' ', $string);   \/\/ --- replace with space\n    $string = str_replace(\"\\t\", ' ', $string);   \/\/ --- replace with space\n    \n    \/\/ ----- remove multiple spaces ----- \n    $string = trim(preg_replace('\/ {2,}\/', ' ', $string));\n    \n    return $string; \n}\n\/\/ -------------------------------------------------------------- \n?&gt;\nthe KEY is the regex pattern: '\/&lt;[^&gt;]*&gt;\/'\ninstead of strip_tags() \n... then remove control characters and multiple spaces\n:)<\/code><\/pre>\n<p>Contributed By: CEO<\/p>\n<pre><code class=\"lang-php\">Note the different outputs from different versions of the same tag: \n \n&lt;?php \/\/ striptags.php \n$data = '&lt;br&gt;Each&lt;br\/&gt;New&lt;br \/&gt;Line'; \n$new  = strip_tags($data, '&lt;br&gt;'); \nvar_dump($new);  \/\/ OUTPUTS string(21) \"&lt;br&gt;EachNew&lt;br \/&gt;Line\" \n \n&lt;?php \/\/ striptags.php \n$data = '&lt;br&gt;Each&lt;br\/&gt;New&lt;br \/&gt;Line'; \n$new  = strip_tags($data, '&lt;br\/&gt;'); \nvar_dump($new); \/\/ OUTPUTS string(16) \"Each&lt;br\/&gt;NewLine\" \n \n&lt;?php \/\/ striptags.php \n$data = '&lt;br&gt;Each&lt;br\/&gt;New&lt;br \/&gt;Line'; \n$new  = strip_tags($data, '&lt;br \/&gt;'); \nvar_dump($new); \/\/ OUTPUTS string(11) \"EachNewLine\" \n?&gt;<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">Features:\n* allowable tags (as in strip_tags),\n* optional stripping attributes of the allowable tags,\n* optional comment preserving,\n* deleting broken and unclosed tags and comments,\n* optional callback function call for every piece processed allowing for flexible replacements.\n&lt;?php\nfunction better_strip_tags( $str, $allowable_tags = '', $strip_attrs = false, $preserve_comments = false, callable $callback = null ) {\n  $allowable_tags = array_map( 'strtolower', array_filter( \/\/ lowercase\n      preg_split( '\/(?:&gt;|^)\\\\s*(?:&lt;|$)\/', $allowable_tags, -1, PREG_SPLIT_NO_EMPTY ), \/\/ get tag names\n      function( $tag ) { return preg_match( '\/^[a-z][a-z0-9_]*$\/i', $tag ); } \/\/ filter broken\n  ) );\n  $comments_and_stuff = preg_split( '\/(&lt;!--.*?(?:--&gt;|$))\/', $str, -1, PREG_SPLIT_DELIM_CAPTURE );\n  foreach ( $comments_and_stuff as $i =&gt; $comment_or_stuff ) {\n    if ( $i % 2 ) { \/\/ html comment\n      if ( !( $preserve_comments &amp;&amp; preg_match( '\/&lt;!--.*?--&gt;\/', $comment_or_stuff ) ) ) {\n        $comments_and_stuff[$i] = '';\n      }\n    } else { \/\/ stuff between comments\n      $tags_and_text = preg_split( \"\/(&lt;(?:[^&gt;\\\"']++|\\\"[^\\\"]*+(?:\\\"|$)|'[^']*+(?:'|$))*(?:&gt;|$))\/\", $comment_or_stuff, -1, PREG_SPLIT_DELIM_CAPTURE );\n      foreach ( $tags_and_text as $j =&gt; $tag_or_text ) {\n        $is_broken = false;\n        $is_allowable = true;\n        $result = $tag_or_text;\n        if ( $j % 2 ) { \/\/ tag\n          if ( preg_match( \"%^(&lt;\/?)([a-z][a-z0-9_]*)\\\\b(?:[^&gt;\\\"'\/]++|\/+?|\\\"[^\\\"]*\\\"|'[^']*')*?(\/?&gt;)%i\", $tag_or_text, $matches ) ) {\n            $tag = strtolower( $matches[2] );\n            if ( in_array( $tag, $allowable_tags ) ) {\n              if ( $strip_attrs ) {\n                $opening = $matches[1];\n                $closing = ( $opening === '&lt;\/' ) ? '&gt;' : $closing;\n                $result = $opening . $tag . $closing;\n              }\n            } else {\n              $is_allowable = false;\n              $result = '';\n            }\n          } else {\n            $is_broken = true;\n            $result = '';\n          }\n        } else { \/\/ text\n          $tag = false;\n        }\n        if ( !$is_broken &amp;&amp; isset( $callback ) ) {\n          \/\/ allow result modification\n          call_user_func_array( $callback, array( &amp;$result, $tag_or_text, $tag, $is_allowable ) );\n        }\n        $tags_and_text[$j] = $result;\n      }\n      $comments_and_stuff[$i] = implode( '', $tags_and_text );\n    }\n  }\n  $str = implode( '', $comments_and_stuff );\n  return $str;\n}\n?&gt;\nCallback arguments:\n* &amp;$result: contains text to be placed insted of original piece (e.g. empty string for forbidden tags), it can be changed;\n* $tag_or_text: original piece of text or a tag (see below);\n* $tag: false for text between tags, lowercase tag name for tags;\n* $is_allowable: boolean telling if a tag isn't allowed (to avoid double checking), always true for text between tags\nCallback function isn't called for comments and broken tags.\nCaution: the function doesn't fully validate tags (the more so HTML itself), it just force strips those obviously broken (in addition to stripping forbidden tags). If you want to get valid tags then use strip_attrs option, though it doesn't guarantee tags are balanced or used in the appropriate context. For complex logic consider using DOM parser.<\/code><\/pre>\n<h2 id=\"stripcslashes\">PHP <code>stripcslashes()<\/code> Function<\/h2>\n<h3>What does <code>stripcslashes()<\/code> do?<\/h3>\n<p>The PHP <code><code>stripcslashes()<\/code><\/code> function will un-quote string quoted with <code>addcslashes()<\/code>.<\/p>\n<h3>PHP <code>stripcslashes()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> stripcslashes ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>stripcslashes()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string to be unescaped. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>stripcslashes()<\/code> Return Value<\/h3>\n<p>The PHP <code>stripcslashes()<\/code> function returns the unescaped string.<\/p>\n<h2 id=\"stripos\">PHP <code>stripos()<\/code> Function<\/h2>\n<h3>What does <code>stripos()<\/code> do?<\/h3>\n<p>The PHP <code><code>stripos()<\/code><\/code> function will find the position of the first occurrence of a case-insensitive substring in a string.<\/p>\n<h3>PHP <code>stripos()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> stripos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int<\/code><\/pre>\n<h3>PHP <code>stripos()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in. <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 Note that the needle may be a string of one or more characters. <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 If specified, search will start this number of characters counted from the beginning of the string. If the offset is negative, the search will start this number of characters counted from the end of the string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>stripos()<\/code> Return Value<\/h3>\n<p>The PHP <code>stripos()<\/code> function returns the position of where the needle exists relative to the beginnning of the <code class=\"parameter\">haystack<\/code> string (independent of offset). Also note that string positions start at 0, and not 1.<\/p>\n<h3>PHP <code>stripos()<\/code> Working Examples<\/h3>\n<h4>1. stripos() examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$findme    = 'a';\n$mystring1 = 'xyz';\n$mystring2 = 'ABC';\n$pos1 = stripos($mystring1, $findme);\n$pos2 = stripos($mystring2, $findme);\n\/\/ Nope, 'a' is certainly not in 'xyz'\nif ($pos1 === false) {\n    echo \"The string '$findme' was not found in the string '$mystring1'\";\n}\n\/\/ Note our use of ===.  Simply == would not work as expected\n\/\/ because the position of 'a' is the 0th (first) character.\nif ($pos2 !== false) {\n    echo \"We found '$findme' in '$mystring2' at position $pos2\";\n}\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP stripos()<\/code> Function<\/h3>\n<p><strong>7.1.0 \u2014 <\/strong> Support for negative <code class=\"parameter\">offset<\/code>s has been added. <\/p>\n<h3>Important Points about PHP <code>stripos()<\/code> Function<\/h3>\n<ol>\n<li>\n<p>This function may return Boolean <code>FALSE<\/code>, but may also return a non-Boolean value which evaluates to <code>FALSE<\/code>. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.<\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: emperorshishire<\/p>\n<pre><code class=\"lang-php\">I found myself needing to find the first position of multiple needles in one haystack.  So I wrote this little function:\n&lt;?php\nfunction multineedle_stripos($haystack, $needles, $offset=0) {\n    foreach($needles as $needle) {\n        $found[$needle] = stripos($haystack, $needle, $offset);\n    }\n    return $found;\n}\n\/\/ It works as such:\n$haystack = \"The quick brown fox jumps over the lazy dog.\";\n$needle = array(\"fox\", \"dog\", \".\", \"duck\")\nvar_dump(multineedle_stripos($haystack, $needle));\n\/* Output:\n   array(3) {\n     [\"fox\"]=&gt;\n     int(16)\n     [\"dog\"]=&gt;\n     int(40)\n     [\".\"]=&gt;\n     int(43)\n     [\"duck\"]=&gt;\n     bool(false)\n   }\n*\/\n?&gt;<\/code><\/pre>\n<h2 id=\"stripslashes\">PHP <code>stripslashes()<\/code> Function<\/h2>\n<h3>What does <code>stripslashes()<\/code> do?<\/h3>\n<p>The PHP <code><code>stripslashes()<\/code><\/code> function will un-quotes a quoted string.<\/p>\n<h3>PHP <code>stripslashes()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> stripslashes ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>stripslashes()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>stripslashes()<\/code> Return Value<\/h3>\n<p>The PHP <code>stripslashes()<\/code> function returns a string with backslashes stripped off. (<strong>\\&#8217;<\/strong> becomes <strong>&#8216;<\/strong> and so on.) Double backslashes (<strong>\\\\<\/strong>) are made into a single backslash (<strong>\\<\/strong>).<\/p>\n<h3>PHP <code>stripslashes()<\/code> Working Examples<\/h3>\n<h4>1. A stripslashes() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Is your name O\\'reilly?\";\n\/\/ Outputs: Is your name O'reilly?\necho stripslashes($str);\n?&gt;<\/code><\/pre>\n<h4>2. Using stripslashes() on an array<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nfunction stripslashes_deep($value)\n{\n    $value = is_array($value) ?\n                array_map('stripslashes_deep', $value) :\n                stripslashes($value);\n    return $value;\n}\n\/\/ Example\n$array = array(\"f\\\\'oo\", \"b\\\\'ar\", array(\"fo\\\\'o\", \"b\\\\'ar\"));\n$array = stripslashes_deep($array);\n\/\/ Output\nprint_r($array);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">Array\n(\n [0] =&gt; f'oo\n [1] =&gt; b'ar\n [2] =&gt; Array\n (\n [0] =&gt; fo'o\n [1] =&gt; b'ar\n )\n)<\/code><\/pre>\n<h3>Important Points about PHP <code>stripslashes()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> If magic_quotes_sybase is on, no backslashes are stripped off but two apostrophes are replaced by one instead. <\/p>\n<\/li>\n<li>\n<p> <code>stripslashes()<\/code> is not recursive. If you want to apply this function to a multi-dimensional array, you need to use a recursive function. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: ivijan dot stefan<\/p>\n<pre><code class=\"lang-php\">Sometimes for some reason is happens that PHP or Javascript or some naughty insert a lot of  backslash. Ordinary function does not notice that. Therefore, it is necessary that the bit \"inflate\":\n&lt;?php\nfunction removeslashes($string)\n{\n    $string=implode(\"\",explode(\"\\\\\",$string));\n    return stripslashes(trim($string));\n}\n\/* Example *\/\n$text=\"My dog don\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'t like the postman!\";\necho removeslashes($text);\n?&gt;\nRESULT: My dog don't like the postman!\nThis flick has served me wery well, because I had this problem before.<\/code><\/pre>\n<h2 id=\"stristr\">PHP <code>stristr()<\/code> Function<\/h2>\n<h3>What does <code>stristr()<\/code> do?<\/h3>\n<p>The PHP <code><code>stristr()<\/code><\/code> function will give you all of <code class=\"parameter\">haystack<\/code> starting from and including the first occurrence of <code class=\"parameter\">needle<\/code> to the end.<\/p>\n<h3>PHP <code>stristr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> stristr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>stristr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to <code>chr()<\/code> should be performed. <\/p>\n<\/li>\n<li>\n<p><code>before_needle<\/code> \u2014 If TRUE, <code>stristr()<\/code> returns the part of the haystack before the first occurrence of the needle (excluding needle). <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>stristr()<\/code> Return Value<\/h3>\n<p>The PHP <code>stristr()<\/code> function returns the matched substring. If <code class=\"parameter\">needle<\/code> is not found, return <code>FALSE<\/code>.<\/p>\n<h3>PHP <code>stristr()<\/code> Working Examples<\/h3>\n<h4>1. stristr() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n  $email = 'USER@EXAMPLE.com';\n  echo stristr($email, 'e'); \/\/ outputs ER@EXAMPLE.com\n  echo stristr($email, 'e', true); \/\/ As of PHP 5.3.0, outputs US\n?&gt;<\/code><\/pre>\n<h4>2. Testing if a string is found or not<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n  $string = 'Hello World!';\n  if(stristr($string, 'earth') === FALSE) {\n    echo '\"earth\" not found in string';\n  }\n\/\/ outputs: \"earth\" not found in string\n?&gt;<\/code><\/pre>\n<h4>3. Using a non &#8220;string&#8221; needle<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n  $string = 'APPLE';\n  echo stristr($string, 97); \/\/ 97 = lowercase a\n\/\/ outputs: APPLE\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP stristr()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> Added the optional parameter <code class=\"parameter\">before_needle<\/code>. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">There was a change in PHP 4.2.3 that can cause a warning message\nto be generated when using stristr(), even though no message was\ngenerated in older versions of PHP.\nThe following will generate a warning message in 4.0.6 and 4.2.3:\n  stristr(\"haystack\", \"\");\n     OR\n  $needle = \"\";  stristr(\"haystack\", $needle);\nThis will _not_ generate an \"Empty Delimiter\" warning message in\n4.0.6, but _will_ in 4.2.3:\n  unset($needle); stristr(\"haystack\", $needle);\nHere's a URL that documents what was changed:\nhttp:\/\/groups.google.ca\/groups?selm=cvshholzgra1031224321%40cvsserver<\/code><\/pre>\n<h2 id=\"strlen\">PHP <code>strlen()<\/code> Function<\/h2>\n<h3>What does <code>strlen()<\/code> do?<\/h3>\n<p>The PHP <code><code>strlen()<\/code><\/code> function will give you the length of the given <code class=\"parameter\">string<\/code>.<\/p>\n<h3>PHP <code>strlen()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strlen ( string $string ) : int<\/code><\/pre>\n<h3>PHP <code>strlen()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The string being measured for length. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strlen()<\/code> Return Value<\/h3>\n<p>The PHP <code>strlen()<\/code> function returns the length of the <code class=\"parameter\">string<\/code> on success, and <strong>0<\/strong> if the <code class=\"parameter\">string<\/code> is empty.<\/p>\n<h3>PHP <code>strlen()<\/code> Working Examples<\/h3>\n<h4>1. A strlen() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = 'abcdef';\necho strlen($str); \/\/ 6\n$str = ' ab cd ';\necho strlen($str); \/\/ 7\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP strlen()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> Prior versions treated arrays as the string Array, thus returning a string length of 5 and emitting an <code>E_NOTICE<\/code> level error. <\/p>\n<h3>Important Points about PHP <code>strlen()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> <code>strlen()<\/code> returns the number of bytes rather than the number of characters in a string. <\/p>\n<\/li>\n<li>\n<p> <code>strlen()<\/code> returns <code>NULL<\/code> when executed on arrays, and an <code>E_WARNING<\/code> level error is emitted. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: rm dot nasir<\/p>\n<pre><code class=\"lang-php\">I want to share something seriously important for newbies or beginners of PHP who plays with strings of UTF8 encoded characters or the languages like: Arabic, Persian, Pashto, Dari, Chinese (simplified), Chinese (traditional), Japanese, Vietnamese, Urdu, Macedonian, Lithuanian, and etc.\nAs the manual says: \"strlen() returns the number of bytes rather than the number of characters in a string.\", so if you want to get the number of characters in a string of UTF8 so use mb_strlen() instead of strlen().\nExample:\n&lt;?php\n\/\/ the Arabic (Hello) string below is: 59 bytes and 32 characters\n$utf8 = \"\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u06cc\u06a9\u0645 \u0648\u0631\u062d\u0645\u0629 \u0627\u0644\u0644\u0647 \u0648\u0628\u0631\u06a9\u0627\u062a\u0647!\";\nvar_export( strlen($utf8) ); \/\/ 59\necho \"&lt;br&gt;\";\nvar_export( mb_strlen($utf8, 'utf8') ); \/\/ 32\n?&gt;<\/code><\/pre>\n<p>Contributed By: chernyshevsky<\/p>\n<pre><code class=\"lang-php\">The easiest way to determine the character count of a UTF8 string is to pass the text through utf8_decode() first: \n \n&lt;?php \n$length = strlen(utf8_decode($s)); \n?&gt; \n \nutf8_decode() converts characters that are not in ISO-8859-1 to '?', which, for the purpose of counting, is quite alright.<\/code><\/pre>\n<p>Contributed By: basil<\/p>\n<pre><code class=\"lang-php\">We just ran into what we thought was a bug but turned out to be a documented difference in behavior between PHP 5.2 &amp; 5.3.  Take the following code example:\n&lt;?php\n$attributes = array('one', 'two', 'three');\nif (strlen($attributes) == 0 &amp;&amp; !is_bool($attributes)) {\n    echo \"We are in the 'if'\\n\";  \/\/  PHP 5.3\n} else {\n    echo \"We are in the 'else'\\n\";  \/\/  PHP 5.2\n}\n?&gt;\nThis is because in 5.2 strlen will automatically cast anything passed to it as a string, and casting an array to a string yields the string \"Array\".  In 5.3, this changed, as noted in the following point in the backward incompatible changes in 5.3 (http:\/\/www.php.net\/manual\/en\/migration53.incompatible.php):\n\"The newer internal parameter parsing API has been applied across all the extensions bundled with PHP 5.3.x. This parameter parsing API causes functions to return NULL when passed incompatible parameters. There are some exceptions to this rule, such as the get_class() function, which will continue to return FALSE on error.\"\nSo, in PHP 5.3, strlen($attributes) returns NULL, while in PHP 5.2, strlen($attributes) returns the integer 5.  This likely affects other functions, so if you are getting different behaviors or new bugs suddenly, check if you have upgraded to 5.3 (which we did recently), and then check for some warnings in your logs like this:\nstrlen() expects parameter 1 to be string, array given in \/var\/www\/sis\/lib\/functions\/advanced_search_lib.php on line 1028\nIf so, then you are likely experiencing this changed behavior.<\/code><\/pre>\n<p>Contributed By: vcardillo<\/p>\n<pre><code class=\"lang-php\">I would like to demonstrate that you need more than just this function in order to truly test for an empty string. The reason being that &lt;?php strlen(null); ?&gt; will return 0. So how do you know if the value was null, or truly an empty string?\n&lt;?php\n$foo = null;\n$len = strlen(null);\n$bar = '';\necho \"Length: \" . strlen($foo) . \"&lt;br&gt;\";\necho \"Length: $len &lt;br&gt;\";\necho \"Length: \" . strlen(null) . \"&lt;br&gt;\";\nif (strlen($foo) === 0) echo 'Null length is Zero &lt;br&gt;';\nif ($len === 0) echo 'Null length is still Zero &lt;br&gt;';\nif (strlen($foo) == 0 &amp;&amp; !is_null($foo)) echo '!is_null(): $foo is truly an empty string &lt;br&gt;';\nelse echo '!is_null(): $foo is probably null &lt;br&gt;';\nif (strlen($foo) == 0 &amp;&amp; isset($foo)) echo 'isset(): $foo is truly an empty string &lt;br&gt;';\nelse echo 'isset(): $foo is probably null &lt;br&gt;';\nif (strlen($bar) == 0 &amp;&amp; !is_null($bar)) echo '!is_null(): $bar is truly an empty string &lt;br&gt;';\nelse echo '!is_null(): $foo is probably null &lt;br&gt;';\nif (strlen($bar) == 0 &amp;&amp; isset($bar)) echo 'isset(): $bar is truly an empty string &lt;br&gt;';\nelse echo 'isset(): $foo is probably null &lt;br&gt;';\n?&gt;\n\/\/ Begin Output:\nLength: 0\nLength: 0 \nLength: 0\nNull length is Zero \nNull length is still Zero \n!is_null(): $foo is probably null \nisset(): $foo is probably null \n!is_null(): $bar is truly an empty string \nisset(): $bar is truly an empty string \n\/\/ End Output\nSo it would seem you need either is_null() or isset() in addition to strlen() if you care whether or not the original value was null.<\/code><\/pre>\n<p>Contributed By: jasonrohrer<\/p>\n<pre><code class=\"lang-php\">PHP's strlen function behaves differently than the C strlen function in terms of its handling of null bytes ('\\0').  \nIn PHP, a null byte in a string does NOT count as the end of the string, and any null bytes are included in the length of the string.\nFor example, in PHP:\nstrlen( \"te\\0st\" ) = 5\nIn C, the same call would return 2.\nThus, PHP's strlen function can be used to find the number of bytes in a binary string (for example, binary data returned by base64_decode).<\/code><\/pre>\n<p>Contributed By: tux<\/p>\n<pre><code class=\"lang-php\">Attention with utf8:\n$foo = \"b\u00e4r\";\nstrlen($foo) will return 4 and not 3 as expected..<\/code><\/pre>\n<h2 id=\"strnatcasecmp\">PHP <code>strnatcasecmp()<\/code> Function<\/h2>\n<h3>What does <code>strnatcasecmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strnatcasecmp()<\/code><\/code> function will case insensitive string comparisons using a &#8220;natural order&#8221; algorithm.<\/p>\n<h3>PHP <code>strnatcasecmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strnatcasecmp ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<h3>PHP <code>strnatcasecmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strnatcasecmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strnatcasecmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code> &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h2 id=\"strnatcmp\">PHP <code>strnatcmp()<\/code> Function<\/h2>\n<h3>What does <code>strnatcmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strnatcmp()<\/code><\/code> function will string comparisons using a &#8220;natural order&#8221; algorithm.<\/p>\n<h3>PHP <code>strnatcmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strnatcmp ( string $str1 , string $str2 ) : int<\/code><\/pre>\n<h3>PHP <code>strnatcmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strnatcmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strnatcmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h2 id=\"strncasecmp\">PHP <code>strncasecmp()<\/code> Function<\/h2>\n<h3>What does <code>strncasecmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strncasecmp()<\/code><\/code> function will binary safe case-insensitive string comparison of the first n characters.<\/p>\n<h3>PHP <code>strncasecmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strncasecmp ( string $str1 , string $str2 , int $len ) : int<\/code><\/pre>\n<h3>PHP <code>strncasecmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<li>\n<p><code>len<\/code> \u2014 The length of strings to be used in the comparison. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strncasecmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strncasecmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h2 id=\"strncmp\">PHP <code>strncmp()<\/code> Function<\/h2>\n<h3>What does <code>strncmp()<\/code> do?<\/h3>\n<p>The PHP <code><code>strncmp()<\/code><\/code> function will binary safe string comparison of the first n characters.<\/p>\n<h3>PHP <code>strncmp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strncmp ( string $str1 , string $str2 , int $len ) : int<\/code><\/pre>\n<h3>PHP <code>strncmp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str1<\/code> \u2014 The first string. <\/p>\n<\/li>\n<li>\n<p><code>str2<\/code> \u2014 The second string. <\/p>\n<\/li>\n<li>\n<p><code>len<\/code> \u2014 Number of characters to use in the comparison. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strncmp()<\/code> Return Value<\/h3>\n<p>The PHP <code>strncmp()<\/code> function returns &lt; 0 if <code class=\"parameter\">str1<\/code> is less than <code class=\"parameter\">str2<\/code>; &gt; 0 if <code class=\"parameter\">str1<\/code> is greater than <code class=\"parameter\">str2<\/code>, and 0 if they are equal.<\/p>\n<h2 id=\"strpbrk\">PHP <code>strpbrk()<\/code> Function<\/h2>\n<h3>What does <code>strpbrk()<\/code> do?<\/h3>\n<p>The PHP <code><code>strpbrk()<\/code><\/code> function will search a string for any of a set of characters.<\/p>\n<h3>PHP <code>strpbrk()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strpbrk ( string $haystack , string $char_list ) : string<\/code><\/pre>\n<h3>PHP <code>strpbrk()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string where char_list is looked for. <\/p>\n<\/li>\n<li>\n<p><code>char_list<\/code> \u2014 This parameter is case sensitive. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strpbrk()<\/code> Return Value<\/h3>\n<p>The PHP <code>strpbrk()<\/code> function returns a string starting from the character found, or <code>FALSE<\/code> if it is not found.<\/p>\n<h3>PHP <code>strpbrk()<\/code> Working Examples<\/h3>\n<h4>1. strpbrk() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = 'This is a Simple text.';\n\/\/ this echoes \"is is a Simple text.\" because 'i' is matched first\necho strpbrk($text, 'mi');\n\/\/ this echoes \"Simple text.\" because chars are case sensitive\necho strpbrk($text, 'S');\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: devnuhl<\/p>\n<pre><code class=\"lang-php\">If you're not looking to duplicate the rest of the string, but instead just want the offset, in the spirit of the str*pos() functions, use strcspn()<\/code><\/pre>\n<h2 id=\"strpos\">PHP <code>strpos()<\/code> Function<\/h2>\n<h3>What does <code>strpos()<\/code> do?<\/h3>\n<p>The PHP <code><code>strpos()<\/code><\/code> function will find the position of the first occurrence of a substring in a string.<\/p>\n<h3>PHP <code>strpos()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int<\/code><\/pre>\n<h3>PHP <code>strpos()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in. <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to <code>chr()<\/code> should be performed. <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 If specified, search will start this number of characters counted from the beginning of the string. If the offset is negative, the search will start this number of characters counted from the end of the string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strpos()<\/code> Return Value<\/h3>\n<p>The PHP <code>strpos()<\/code> function returns the position of where the needle exists relative to the beginning of the <code class=\"parameter\">haystack<\/code> string (independent of offset). Also note that string positions start at 0, and not 1.<\/p>\n<h3>PHP <code>strpos()<\/code> Working Examples<\/h3>\n<h4>1. Using ===<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$mystring = 'abc';\n$findme   = 'a';\n$pos = strpos($mystring, $findme);\n\/\/ Note our use of ===.  Simply == would not work as expected\n\/\/ because the position of 'a' was the 0th (first) character.\nif ($pos === false) {\n    echo \"The string '$findme' was not found in the string '$mystring'\";\n} else {\n    echo \"The string '$findme' was found in the string '$mystring'\";\n    echo \" and exists at position $pos\";\n}\n?&gt;<\/code><\/pre>\n<h4>2. Using !==<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$mystring = 'abc';\n$findme   = 'a';\n$pos = strpos($mystring, $findme);\n\/\/ The !== operator can also be used.  Using != would not work as expected\n\/\/ because the position of 'a' is 0. The statement (0 != false) evaluates \n\/\/ to false.\nif ($pos !== false) {\n     echo \"The string '$findme' was found in the string '$mystring'\";\n         echo \" and exists at position $pos\";\n} else {\n     echo \"The string '$findme' was not found in the string '$mystring'\";\n}\n?&gt;<\/code><\/pre>\n<h4>3. Using an offset<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ We can search for the character, ignoring anything before the offset\n$newstring = 'abcdef abcdef';\n$pos = strpos($newstring, 'a', 1); \/\/ $pos = 7, not 0\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP strpos()<\/code> Function<\/h3>\n<p><strong>7.1.0 \u2014 <\/strong> Support for negative <code class=\"parameter\">offset<\/code>s has been added. <\/p>\n<h3>Important Points about PHP <code>strpos()<\/code> Function<\/h3>\n<ol>\n<li>\n<p>This function may return Boolean <code>FALSE<\/code>, but may also return a non-Boolean value which evaluates to <code>FALSE<\/code>. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.<\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Suggested re-write for pink WARNING box<\/p>\n<pre><code class=\"lang-php\">WARNING\nAs strpos may return either FALSE (substring absent) or 0 (substring at start of string), strict versus loose equivalency operators must be used very carefully.\nTo know that a substring is absent, you must use:  \n=== FALSE\nTo know that a substring is present (in any position including 0), you can use either of:\n!== FALSE  (recommended)\n &gt; -1  (note: or greater than any negative number)\nTo know that a substring is at the start of the string, you must use:  \n=== 0\nTo know that a substring is in any position other than the start, you can use any of: \n &gt; 0  (recommended)\n!= 0  (note: but not !== 0 which also equates to FALSE)\n!= FALSE  (disrecommended as highly confusing)\nAlso note that you cannot compare a value of \"\" to the returned value of strpos. With a loose equivalence operator (== or !=) it will return results which don't distinguish between the substring's presence versus position. With a strict equivalence operator (=== or !==) it will always return false.<\/code><\/pre>\n<p>Contributed By: martijn<\/p>\n<pre><code class=\"lang-php\">This is a function I wrote to find all occurrences of a string, using strpos recursively.\n&lt;?php\nfunction strpos_recursive($haystack, $needle, $offset = 0, &amp;$results = array()) {                \n    $offset = strpos($haystack, $needle, $offset);\n    if($offset === false) {\n        return $results;            \n    } else {\n        $results[] = $offset;\n        return strpos_recursive($haystack, $needle, ($offset + 1), $results);\n    }\n}\n?&gt;\nThis is how you use it:\n&lt;?php\n$string = 'This is some string';\n$search = 'a';\n$found = strpos_recursive($string, $search);\nif($found) {\n    foreach($found as $pos) {\n        echo 'Found \"'.$search.'\" in string \"'.$string.'\" at position &lt;b&gt;'.$pos.'&lt;\/b&gt;&lt;br \/&gt;';\n    }    \n} else {\n    echo '\"'.$search.'\" not found in \"'.$string.'\"';\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: fabio<\/p>\n<pre><code class=\"lang-php\">It is interesting to be aware of the behavior when the treatment of strings with characters using different encodings.\n&lt;?php\n# Works like expected. There is no accent\nvar_dump(strpos(\"Fabio\", 'b'));\n#int(2)\n# The \"\u00e1\" letter is occupying two positions\nvar_dump(strpos(\"F\u00e1bio\", 'b')) ;\n#int(3)\n# Now, encoding the string \"F\u00e1bio\" to utf8, we get some \"unexpected\" outputs. Every letter that is no in regular ASCII table, will use 4 positions(bytes). The starting point remains like before.\n# We cant find the characted, because the haystack string is now encoded.\nvar_dump(strpos(utf8_encode(\"F\u00e1bio\"), '\u00e1'));\n#bool(false)\n# To get the expected result, we need to encode the needle too\nvar_dump(strpos(utf8_encode(\"F\u00e1bio\"), utf8_encode('\u00e1')));\n#int(1) \n# And, like said before, \"\u00e1\" occupies 4 positions(bytes)\nvar_dump(strpos(utf8_encode(\"F\u00e1bio\"), 'b'));\n#int(5)<\/code><\/pre>\n<p>Contributed By: mtroy dot student<\/p>\n<pre><code class=\"lang-php\">When you want to know how much of substring occurrences, you'll use \"substr_count\".\nBut, retrieve their positions, will be harder.\nSo, you can do it by starting with the last occurrence :\nfunction strpos_r($haystack, $needle)\n{\n    if(strlen($needle) &gt; strlen($haystack))\n        trigger_error(sprintf(\"%s: length of argument 2 must be &lt;= argument 1\", __FUNCTION__), E_USER_WARNING);\n    $seeks = array();\n    while($seek = strrpos($haystack, $needle))\n    {\n        array_push($seeks, $seek);\n        $haystack = substr($haystack, 0, $seek);\n    }\n    return $seeks;\n}\nit will return an array of all occurrences a the substring in the string\nExample : \n$test = \"this is a test for testing a test function... blah blah\";\nvar_dump(strpos_r($test, \"test\"));\n\/\/ output \narray(3) {\n  [0]=&gt;\n  int(29)\n  [1]=&gt;\n  int(19)\n  [2]=&gt;\n  int(10)\n}\nPaul-antoine\nMal\u00e9zieux.<\/code><\/pre>\n<p>Contributed By: rjeggens<\/p>\n<pre><code class=\"lang-php\">I lost an hour before I noticed that strpos only returns FALSE as a boolean, never TRUE.. This means that\nstrpos() !== false \nis a different beast then:\nstrpos() === true\nsince the latter will never be true. After I found out, The warning in the documentation made a lot more sense.<\/code><\/pre>\n<p>Contributed By: akarmenia<\/p>\n<pre><code class=\"lang-php\">My version of strpos with needles as an array. Also allows for a string, or an array inside an array.\n&lt;?php\nfunction strpos_array($haystack, $needles) {\n    if ( is_array($needles) ) {\n        foreach ($needles as $str) {\n            if ( is_array($str) ) {\n                $pos = strpos_array($haystack, $str);\n            } else {\n                $pos = strpos($haystack, $str);\n            }\n            if ($pos !== FALSE) {\n                return $pos;\n            }\n        }\n    } else {\n        return strpos($haystack, $needles);\n    }\n}\n\/\/ Test\necho strpos_array('This is a test', array('test', 'drive')); \/\/ Output is 10\n?&gt;<\/code><\/pre>\n<h2 id=\"strrchr\">PHP <code>strrchr()<\/code> Function<\/h2>\n<h3>What does <code>strrchr()<\/code> do?<\/h3>\n<p>The PHP <code><code>strrchr()<\/code><\/code> function will find the last occurrence of a character in a string.<\/p>\n<h3>PHP <code>strrchr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strrchr ( string $haystack , mixed $needle ) : string<\/code><\/pre>\n<h3>PHP <code>strrchr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle contains more than one character, only the first is used. This behavior is different from that of <code>strstr()<\/code>. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strrchr()<\/code> Return Value<\/h3>\n<p>The PHP <code>strrchr()<\/code> function returns the portion of string, or <code>FALSE<\/code> if <code class=\"parameter\">needle<\/code> is not found.<\/p>\n<h3>PHP <code>strrchr()<\/code> Working Examples<\/h3>\n<h4>1. strrchr() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ get last directory in $PATH\n$dir = substr(strrchr($PATH, \":\"), 1);\n\/\/ get everything after last newline\n$text = \"Line 1\\nLine 2\\nLine 3\";\n$last = substr(strrchr($text, 10), 1 );\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jphansen<\/p>\n<pre><code class=\"lang-php\">To extract your portion of a string without the actual character you searched for, you can use:\n&lt;?php\n$path = '\/www\/public_html\/index.html';\n$filename = substr(strrchr($path, \"\/\"), 1);\necho $filename; \/\/ \"index.html\"\n?&gt;<\/code><\/pre>\n<p>Contributed By: matthewkastor<\/p>\n<pre><code class=\"lang-php\">&lt;?php \n\/** \n * Removes the preceeding or proceeding portion of a string \n * relative to the last occurrence of the specified character. \n * The character selected may be retained or discarded. \n * \n * Example usage: \n * &lt;code&gt; \n * $example = 'http:\/\/example.com\/path\/file.php'; \n * $cwd_relative[] = cut_string_using_last('\/', $example, 'left', true); \n * $cwd_relative[] = cut_string_using_last('\/', $example, 'left', false); \n * $cwd_relative[] = cut_string_using_last('\/', $example, 'right', true); \n * $cwd_relative[] = cut_string_using_last('\/', $example, 'right', false); \n * foreach($cwd_relative as $string) { \n *     echo \"$string &lt;br&gt;\".PHP_EOL; \n * } \n * &lt;\/code&gt; \n * \n * Outputs: \n * &lt;code&gt; \n * http:\/\/example.com\/path\/ \n * http:\/\/example.com\/path \n * \/file.php \n * file.php \n * &lt;\/code&gt; \n * \n * @param string $character the character to search for. \n * @param string $string the string to search through. \n * @param string $side determines whether text to the left or the right of the character is returned. \n * Options are: left, or right. \n * @param bool $keep_character determines whether or not to keep the character. \n * Options are: true, or false. \n * @return string \n *\/ \nfunction cut_string_using_last($character, $string, $side, $keep_character=true) { \n    $offset = ($keep_character ? 1 : 0); \n    $whole_length = strlen($string); \n    $right_length = (strlen(strrchr($string, $character)) - 1); \n    $left_length = ($whole_length - $right_length - 1); \n    switch($side) { \n        case 'left': \n            $piece = substr($string, 0, ($left_length + $offset)); \n            break; \n        case 'right': \n            $start = (0 - ($right_length + $offset)); \n            $piece = substr($string, $start); \n            break; \n        default: \n            $piece = false; \n            break; \n    } \n    return($piece); \n} \n?&gt;<\/code><\/pre>\n<h2 id=\"strrev\">PHP <code>strrev()<\/code> Function<\/h2>\n<h3>What does <code>strrev()<\/code> do?<\/h3>\n<p>The PHP <code><code>strrev()<\/code><\/code> function will give you <code class=\"parameter\">string<\/code>, reversed.<\/p>\n<h3>PHP <code>strrev()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strrev ( string $string ) : string<\/code><\/pre>\n<h3>PHP <code>strrev()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The string to be reversed. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strrev()<\/code> Return Value<\/h3>\n<p>The PHP <code>strrev()<\/code> function returns the reversed string.<\/p>\n<h3>PHP <code>strrev()<\/code> Working Examples<\/h3>\n<h4>1. Reversing a string with strrev()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho strrev(\"Hello world!\"); \/\/ outputs \"!dlrow olleH\"\n?&gt;<\/code><\/pre>\n<h2 id=\"strripos\">PHP <code>strripos()<\/code> Function<\/h2>\n<h3>What does <code>strripos()<\/code> do?<\/h3>\n<p>The PHP <code><code>strripos()<\/code><\/code> function will find the position of the last occurrence of a case-insensitive substring in a string.<\/p>\n<h3>PHP <code>strripos()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strripos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int<\/code><\/pre>\n<h3>PHP <code>strripos()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in. <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to <code>chr()<\/code> should be performed. <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 If zero or positive, the search is performed left to right skipping the first offset bytes of the haystack. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strripos()<\/code> Return Value<\/h3>\n<p>The PHP <code>strripos()<\/code> function returns the position where the needle exists relative to the beginnning of the <code class=\"parameter\">haystack<\/code> string (independent of search direction or offset).<\/p>\n<h3>PHP <code>strripos()<\/code> Working Examples<\/h3>\n<h4>1. A simple strripos() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$haystack = 'ababcd';\n$needle   = 'aB';\n$pos      = strripos($haystack, $needle);\nif ($pos === false) {\n    echo \"Sorry, we did not find ($needle) in ($haystack)\";\n} else {\n    echo \"Congratulations!\\n\";\n    echo \"We found the last ($needle) in ($haystack) at position ($pos)\";\n}\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\"> Congratulations!\n We found the last (aB) in (ababcd) at position (2)<\/code><\/pre>\n<h3>Important Points about PHP <code>strripos()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> This is effectively looking for the last occurrence of <code class=\"parameter\">needle<\/code> before the last <code class=\"parameter\">offset<\/code> bytes. <\/p>\n<\/li>\n<li>\n<p>This function may return Boolean <code>FALSE<\/code>, but may also return a non-Boolean value which evaluates to <code>FALSE<\/code>. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.<\/p>\n<\/li>\n<\/ol>\n<h2 id=\"strrpos\">PHP <code>strrpos()<\/code> Function<\/h2>\n<h3>What does <code>strrpos()<\/code> do?<\/h3>\n<p>The PHP <code><code>strrpos()<\/code><\/code> function will find the position of the last occurrence of a substring in a string.<\/p>\n<h3>PHP <code>strrpos()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strrpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int<\/code><\/pre>\n<h3>PHP <code>strrpos()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in. <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to <code>chr()<\/code> should be performed. <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 If zero or positive, the search is performed left to right skipping the first offset bytes of the haystack. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strrpos()<\/code> Return Value<\/h3>\n<p>The PHP <code>strrpos()<\/code> function returns the position where the needle exists relative to the beginning of the <code class=\"parameter\">haystack<\/code> string (independent of search direction or offset).<\/p>\n<h3>PHP <code>strrpos()<\/code> Working Examples<\/h3>\n<h4>1. Checking if a needle is in the haystack<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$pos = strrpos($mystring, \"b\");\nif ($pos === false) { \/\/ note: three equal signs\n    \/\/ not found...\n}\n?&gt;<\/code><\/pre>\n<h4>2. Searching with offsets<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$foo = \"0123456789a123456789b123456789c\";\n\/\/ Looking for '0' from the 0th byte (from the beginning)\nvar_dump(strrpos($foo, '0', 0));\n\/\/ Looking for '0' from the 1st byte (after byte \"0\")\nvar_dump(strrpos($foo, '0', 1));\n\/\/ Looking for '7' from the 21th byte (after byte 20)\nvar_dump(strrpos($foo, '7', 20));\n\/\/ Looking for '7' from the 29th byte (after byte 28)\nvar_dump(strrpos($foo, '7', 28));\n\/\/ Looking for '7' right to left from the 5th byte from the end\nvar_dump(strrpos($foo, '7', -5));\n\/\/ Looking for 'c' right to left from the 2nd byte from the end\nvar_dump(strrpos($foo, 'c', -2));\n\/\/ Looking for '9c' right to left from the 2nd byte from the end\nvar_dump(strrpos($foo, '9c', -2));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">int(0)\nbool(false)\nint(27)\nbool(false)\nint(17)\nbool(false)\nint(29)<\/code><\/pre>\n<h3>Important Points about PHP <code>strrpos()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> This is effectively looking for the last occurrence of <code class=\"parameter\">needle<\/code> before the last <code class=\"parameter\">offset<\/code> bytes. <\/p>\n<\/li>\n<li>\n<p>This function may return Boolean <code>FALSE<\/code>, but may also return a non-Boolean value which evaluates to <code>FALSE<\/code>. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.<\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: brian<\/p>\n<pre><code class=\"lang-php\">The documentation for 'offset' is misleading.\nIt says, \"offset may be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.\"\nThis is confusing if you think of strrpos as starting at the end of the string and working backwards.\nA better way to think of offset is:\n- If offset is positive, then strrpos only operates on the part of the string from offset to the end. This will usually have the same results as not specifying an offset, unless the only occurences of needle are before offset (in which case specifying the offset won't find the needle).\n- If offset is negative, then strrpos only operates on that many characters at the end of the string. If the needle is farther away from the end of the string, it won't be found.\nIf, for example, you want to find the last space in a string before the 50th character, you'll need to do something like this:\nstrrpos($text, \" \", -(strlen($text) - 50));\nIf instead you used strrpos($text, \" \", 50), then you would find the last space between the 50th character and the end of the string, which may not have been what you were intending.<\/code><\/pre>\n<h2 id=\"strspn\">PHP <code>strspn()<\/code> Function<\/h2>\n<h3>What does <code>strspn()<\/code> do?<\/h3>\n<p>The PHP <code><code>strspn()<\/code><\/code> function will finds the length of the initial segment of a string consisting entirely of characters contained within a given mask .<\/p>\n<h3>PHP <code>strspn()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strspn ( string $subject , string $mask [, int $start [, int $length ]] ) : int<\/code><\/pre>\n<h3>PHP <code>strspn()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>subject<\/code> \u2014 The string to examine. <\/p>\n<\/li>\n<li>\n<p><code>mask<\/code> \u2014 The list of allowable characters. <\/p>\n<\/li>\n<li>\n<p><code>start<\/code> \u2014 The position in subject to start searching. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 The length of the segment from subject to examine. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strspn()<\/code> Return Value<\/h3>\n<p>The PHP <code>strspn()<\/code> function returns the length of the initial segment of <code class=\"parameter\">subject<\/code> which consists entirely of characters in <code class=\"parameter\">mask<\/code>.<\/p>\n<h3>PHP <code>strspn()<\/code> Working Examples<\/h3>\n<h4>1. strspn() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ subject does not start with any characters from mask\nvar_dump(strspn(\"foo\", \"o\"));\n\/\/ examine two characters from subject starting at offset 1\nvar_dump(strspn(\"foo\", \"o\", 1, 2));\n\/\/ examine one character from subject starting at offset 1\nvar_dump(strspn(\"foo\", \"o\", 1, 1));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">int(0)\nint(2)\nint(1)<\/code><\/pre>\n<h3>Important Points about PHP <code>strspn()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> When a <code class=\"parameter\">start<\/code> parameter is set, the returned length is counted starting from this position, not from the beginning of <code class=\"parameter\">subject<\/code>. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">You can use this function with strlen to check illegal characters, string lenght must be the same than strspn (characters from my string contained in another)\n&lt;?php\n$digits='0123456789';\nif (strlen($phone) != strspn($phone,$digits))\n echo \"illegal characters\";\n?&gt;<\/code><\/pre>\n<p>Contributed By: barry dot balkowski<\/p>\n<pre><code class=\"lang-php\">It took me some time to understand the way this function works\u2026\nI\u2019ve compiled my own explanation with my own words that is more understandable for me personally than the official one or those that can be found in different tutorials on the web.\nPerhaps, it will save someone several minutes\u2026\n&lt;?php \nstrspn(string $haystack, string $char_list [, int $start [, int $length]])\n?&gt;\nThe way it works:\n -   searches for a segment of $haystack that consists entirely from supplied through the second argument chars \n -   $haystack must start from one of the chars supplied through $char_list, otherwise the function will find nothing\n -   as soon as the function encounters a char that was not mentioned in $chars it understands that the segment is over and stops (it doesn\u2019t search for the second, third and so on segments)\n -   finally, it measures the segment\u2019s length and return it (i.e. length)\nIn other words it finds a span (only the first one) in the string that consists entirely form chars supplied in $chars_list and returns its length<\/code><\/pre>\n<h2 id=\"strstr\">PHP <code>strstr()<\/code> Function<\/h2>\n<h3>What does <code>strstr()<\/code> do?<\/h3>\n<p>The PHP <code><code>strstr()<\/code><\/code> function will give you part of <code class=\"parameter\">haystack<\/code> string starting from and including the first occurrence of <code class=\"parameter\">needle<\/code> to the end of <code class=\"parameter\">haystack<\/code>.<\/p>\n<h3>PHP <code>strstr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string<\/code><\/pre>\n<h3>PHP <code>strstr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to <code>chr()<\/code> should be performed. <\/p>\n<\/li>\n<li>\n<p><code>before_needle<\/code> \u2014 If TRUE, <code>strstr()<\/code> returns the part of the haystack before the first occurrence of the needle (excluding the needle). <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strstr()<\/code> Return Value<\/h3>\n<p>The PHP <code>strstr()<\/code> function returns the portion of string, or <code>FALSE<\/code> if <code class=\"parameter\">needle<\/code> is not found.<\/p>\n<h3>PHP <code>strstr()<\/code> Working Examples<\/h3>\n<h4>1. strstr() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$email  = 'name@example.com';\n$domain = strstr($email, '@');\necho $domain; \/\/ prints @example.com\n$user = strstr($email, '@', true); \/\/ As of PHP 5.3.0\necho $user; \/\/ prints name\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP strstr()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> Added the optional parameter <code class=\"parameter\">before_needle<\/code>. <\/p>\n<h3>Important Points about PHP <code>strstr()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> This function is case-sensitive. For case-insensitive searches, use <code>stristr()<\/code>. <\/p>\n<\/li>\n<li>\n<p> If you only want to determine if a particular <code class=\"parameter\">needle<\/code> occurs within <code class=\"parameter\">haystack<\/code>, use the faster and less memory intensive function <code>strpos()<\/code> instead. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: laszlo dot heredy<\/p>\n<pre><code class=\"lang-php\">Strstr() is not a way to avoid type-checking with strpos().\nIf $needle is the last character in $haystack, and testing $needle as a boolean by itself would evaluate to false, then testing strstr() as a boolean will evaluate to false (because, if successful, strstr() returns the first occurrence of $needle along with the rest of $haystack).\n&lt;?php\nfindZero('01234');  \/\/ found a zero\nfindZero('43210');  \/\/ did not find a zero\nfindZero('0');      \/\/ did not find a zero\nfindZero('00');     \/\/ found a zero\nfindZero('000');    \/\/ found a zero\nfindZero('10');     \/\/ did not find a zero\nfindZero('100');    \/\/ found a zero\nfunction findZero($numberString) {\n    if (strstr($numberString, '0')) {\n        echo 'found a zero';\n    } else {\n        echo 'did not find a zero';\n    }\n}\n?&gt;\nAlso, strstr() is far more memory-intensive than strpos(), especially with longer strings as your $haystack, so if you are not interested in the substring that strstr() returns, you shouldn't be using it anyway. \nThere is no PHP function just to check only _if_ $needle occurs in $haystack; strpos() tells you if it _doesn't_ by returning false, but, if it does occur, it tells you _where_ it occurs as an integer, which is 0 (zero) if $needle is the first part of $haystack, which is why testing if (strpos($needle, $haystack)===false) is the only way to know for sure if $needle is not part of $haystack.\nMy advice is to start loving type checking immediately, and to familiarize yourself with the return value of the functions you are using.\nCheers.<\/code><\/pre>\n<p>Contributed By: gruessle<\/p>\n<pre><code class=\"lang-php\">Been using this for years:\n&lt;?php\n\/**\n*\n* @author : Dennis T Kaplan\n*\n* @version : 1.0\n* Date : June 17, 2007\n* Function : reverse strstr()\n* Purpose : Returns part of haystack string from start to the first occurrence of needle\n* $haystack = 'this\/that\/whatever';\n* $result = rstrstr($haystack, '\/')\n* $result == this\n*\n* @access public\n* @param string $haystack, string $needle\n* @return string\n**\/\nfunction rstrstr($haystack,$needle)\n    {\n        return substr($haystack, 0,strpos($haystack, $needle));\n    }\n?&gt;\nYou could change it to:\nrstrstr ( string $haystack , mixed $needle [, int $start] )\n&lt;?php\nfunction rstrstr($haystack,$needle, $start=0)\n    {\n        return substr($haystack, $start,strpos($haystack, $needle));\n    }\n?&gt;<\/code><\/pre>\n<h2 id=\"strtok\">PHP <code>strtok()<\/code> Function<\/h2>\n<h3>What does <code>strtok()<\/code> do?<\/h3>\n<p>The PHP <code><code>strtok()<\/code><\/code> function will <code>strtok()<\/code> splits a string (<code class=\"parameter\">str<\/code>) into smaller strings (tokens), with each token being delimited by any character from <code class=\"parameter\">token<\/code>. That is, if you have a string like &#8220;This is an example string&#8221; you could tokenize this string into its individual words by using the space character as the token.<\/p>\n<h3>PHP <code>strtok()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strtok ( string $str , string $token ) : string<\/code><\/pre>\n<pre><code class=\"lang-php\"> strtok ( string $token ) : string<\/code><\/pre>\n<h3>PHP <code>strtok()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string being split up into smaller strings (tokens). <\/p>\n<\/li>\n<li>\n<p><code>token<\/code> \u2014 The delimiter used when splitting up str. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strtok()<\/code> Return Value<\/h3>\n<p>The PHP <code>strtok()<\/code> function returns a string token.<\/p>\n<h3>PHP <code>strtok()<\/code> Working Examples<\/h3>\n<h4>1. strtok() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$string = \"This is\\tan example\\nstring\";\n\/* Use tab and newline as tokenizing characters as well  *\/\n$tok = strtok($string, \" \\n\\t\");\nwhile ($tok !== false) {\n    echo \"Word=$tok&lt;br \/&gt;\";\n    $tok = strtok(\" \\n\\t\");\n}\n?&gt;<\/code><\/pre>\n<h4>2. strtok() behavior on empty part found<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$first_token  = strtok('\/something', '\/');\n$second_token = strtok('\/');\nvar_dump($first_token, $second_token);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\"> string(9) \"something\"\n bool(false)<\/code><\/pre>\n<h3>Important Points about PHP <code>strtok()<\/code> Function<\/h3>\n<ol>\n<li>\n<p>This function may return Boolean <code>FALSE<\/code>, but may also return a non-Boolean value which evaluates to <code>FALSE<\/code>. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.<\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: eep2004<\/p>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ strtok example\n$str = 'Hello to all of Ukraine';\necho strtok($str, ' ').' '.strtok(' ').' '.strtok(' ');\n?&gt;\nResult:\nHello to all<\/code><\/pre>\n<p>Contributed By: manicdepressive<\/p>\n<pre><code class=\"lang-php\">&lt;pre&gt;&lt;?php\n\/** get leading, trailing, and embedded separator tokens that were 'skipped'\nif for some ungodly reason you are using php to implement a simple parser that \nneeds to detect nested clauses as it builds a parse tree *\/\n$str = \"(((alpha(beta))(gamma))\";\n$seps = '()';\n$tok = strtok( $str,$seps ); \/\/ return false on empty string or null\n$cur = 0;      \n$dumbDone = FALSE;\n$done = (FALSE===$tok);\nwhile (!$done) {\n   \/\/ process skipped tokens (if any at first iteration) (special for last)\n   $posTok = $dumbDone ? strlen($str) : strpos($str, $tok, $cur );\n   $skippedMany = substr( $str, $cur, $posTok-$cur ); \/\/ false when 0 width\n   $lenSkipped = strlen($skippedMany); \/\/ 0 when false\n   if (0!==$lenSkipped) {\n      $last = strlen($skippedMany) -1;\n      for($i=0; $i&lt;=$last; $i++){\n         $skipped = $skippedMany[$i];\n         $cur += strlen($skipped);\n         echo \"skipped: $skipped\\n\";\n      }\n   }\n   if ($dumbDone) break; \/\/ this is the only place the loop is terminated\n   \/\/ process current tok\n   echo \"curr tok: \".$tok.\"\\n\";\n   \/\/ update cursor\n   $cur += strlen($tok);\n   \/\/ get any next tok\n   if (!$dumbDone){\n      $tok = strtok($seps);\n      $dumbDone = (FALSE===$tok); \n      \/\/ you're not really done till you check for trailing skipped\n   }\n};\n?&gt;&lt;\/pre&gt;<\/code><\/pre>\n<h2 id=\"strtolower\">PHP <code>strtolower()<\/code> Function<\/h2>\n<h3>What does <code>strtolower()<\/code> do?<\/h3>\n<p>The PHP <code><code>strtolower()<\/code><\/code> function will give you <code class=\"parameter\">string<\/code> with all alphabetic characters converted to lowercase.<\/p>\n<h3>PHP <code>strtolower()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strtolower ( string $string ) : string<\/code><\/pre>\n<h3>PHP <code>strtolower()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strtolower()<\/code> Return Value<\/h3>\n<p>The PHP <code>strtolower()<\/code> function returns the lowercased string.<\/p>\n<h3>PHP <code>strtolower()<\/code> Working Examples<\/h3>\n<h4>1. strtolower() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Mary Had A Little Lamb and She LOVED It So\";\n$str = strtolower($str);\necho $str; \/\/ Prints mary had a little lamb and she loved it so\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: marcin<\/p>\n<pre><code class=\"lang-php\">Strtolower(); doesn't work for polish chars \n \n&lt;?php strtolower(\"m\u0104kA\"); ?&gt; \nwill return: m\u0104ka; \n \nthe best solution - use mb_strtolower() \n \n&lt;?php mb_strtolower(\"m\u0104kA\",'UTF-8'); ?&gt; \nwill return: m\u0105ka<\/code><\/pre>\n<p>Contributed By: coder<\/p>\n<pre><code class=\"lang-php\">For cyrillic and UTF 8 use  mb_convert_case \n \nexampel \n \n&lt;?php \n$string = \"\u0410\u0432\u0441\u0442\u0440\u0430\u043b\u0438\u044f\"; \n$string = mb_convert_case($string, MB_CASE_LOWER, \"UTF-8\"); \necho $string; \n \n\/\/output is: \u0430\u0432\u0441\u0442\u0440\u0430\u043b\u0438\u044f \n?&gt;<\/code><\/pre>\n<p>Contributed By: helvete<\/p>\n<pre><code class=\"lang-php\">It is worth noting that \n&lt;?php \nvar_dump(strtolower(null))\n?&gt;\nreturns: \nstring(0) \"\"<\/code><\/pre>\n<p>Contributed By: dbers26<\/p>\n<pre><code class=\"lang-php\">The function  arraytolower will create duplicate entries since keys are case sensitive.  \n \n&lt;?php \n$array = array('test1' =&gt; 'asgAFasDAAd', 'TEST2' =&gt; 'ASddhshsDGb', 'TeSt3 '=&gt; 'asdasda@asdadadASDASDgh'); \n \n$array = arraytolower($array); \n?&gt; \n\/* \nArray \n( \n    [test1] =&gt; asgafasdaad \n    [TEST2] =&gt; ASddhshsDGb \n    [TeSt3] =&gt; asdasda@asdadadASDASDgh \n    [test2] =&gt; asddhshsdgb \n    [test3] =&gt; asdasda@asdadadasdasdgh \n) \n*\/ \n \nI prefer this method \n \n&lt;?php \n  function arraytolower($array, $include_leys=false) { \n    \n    if($include_leys) { \n      foreach($array as $key =&gt; $value) { \n        if(is_array($value)) \n          $array2[strtolower($key)] = arraytolower($value, $include_leys); \n        else \n          $array2[strtolower($key)] = strtolower($value); \n      } \n      $array = $array2; \n    } \n    else { \n      foreach($array as $key =&gt; $value) { \n        if(is_array($value)) \n          $array[$key] = arraytolower($value, $include_leys); \n        else \n          $array[$key] = strtolower($value);   \n      } \n    } \n    \n    return $array; \n  } \n?&gt; \n \nwhich when used like this \n \n&lt;?php \n$array = $array = array('test1' =&gt; 'asgAFasDAAd', 'TEST2' =&gt; 'ASddhshsDGb', 'TeSt3 '=&gt; 'asdasda@asdadadASDASDgh'); \n \n$array1 = arraytolower($array); \n$array2 = arraytolower($array,true); \n \nprint_r($array1); \nprint_r($array2); \n?&gt; \n \nwill give output of \n \nArray \n( \n    [test1] =&gt; asgafasdaad \n    [TEST2] =&gt; asddhshsdgb \n    [TeSt3] =&gt; asdasda@asdadadasdasdgh \n) \nArray \n( \n    [test1] =&gt; asgafasdaad \n    [test2] =&gt; asddhshsdgb \n    [test3] =&gt; asdasda@asdadadasdasdgh \n)<\/code><\/pre>\n<h2 id=\"strtoupper\">PHP <code>strtoupper()<\/code> Function<\/h2>\n<h3>What does <code>strtoupper()<\/code> do?<\/h3>\n<p>The PHP <code><code>strtoupper()<\/code><\/code> function will give you <code class=\"parameter\">string<\/code> with all alphabetic characters converted to uppercase.<\/p>\n<h3>PHP <code>strtoupper()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strtoupper ( string $string ) : string<\/code><\/pre>\n<h3>PHP <code>strtoupper()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strtoupper()<\/code> Return Value<\/h3>\n<p>The PHP <code>strtoupper()<\/code> function returns the uppercased string.<\/p>\n<h3>PHP <code>strtoupper()<\/code> Working Examples<\/h3>\n<h4>1. strtoupper() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$str = \"Mary Had A Little Lamb and She LOVED It So\";\n$str = strtoupper($str);\necho $str; \/\/ Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: andre<\/p>\n<pre><code class=\"lang-php\">One might think that setting the correct locale would do the trick with for example german umlauts, but this is not the case. You have to use mb_strtoupper() instead:\n&lt;?php\nsetlocale(LC_CTYPE, 'de_DE.UTF8');\necho strtoupper('Umlaute \u00e4\u00f6\u00fc in uppercase'); \/\/ outputs \"UMLAUTE \u00e4\u00f6\u00fc IN UPPERCASE\"\necho mb_strtoupper('Umlaute \u00e4\u00f6\u00fc in uppercase', 'UTF-8'); \/\/ outputs \"UMLAUTE \u00c4\u00d6\u00dc IN UPPERCASE\"\n?&gt;<\/code><\/pre>\n<p>Contributed By: mec<\/p>\n<pre><code class=\"lang-php\">Something I myself first not thought about:\nif there are any html entities (named entities) in your string, strtoupper will turn all letters within this entities to upper case, too. So if you want to manipulate a string with strtoupper it should contain only unicode entities (if ever).<\/code><\/pre>\n<h2 id=\"strtr\">PHP <code>strtr()<\/code> Function<\/h2>\n<h3>What does <code>strtr()<\/code> do?<\/h3>\n<p>The PHP <code><code>strtr()<\/code><\/code> function will translate characters or replace substrings.<\/p>\n<h3>PHP <code>strtr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> strtr ( string $str , string $from , string $to ) : string<\/code><\/pre>\n<pre><code class=\"lang-php\"> strtr ( string $str , array $replace_pairs ) : string<\/code><\/pre>\n<h3>PHP <code>strtr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string being translated. <\/p>\n<\/li>\n<li>\n<p><code>from<\/code> \u2014 The string being translated to to. <\/p>\n<\/li>\n<li>\n<p><code>to<\/code> \u2014 The string replacing from. <\/p>\n<\/li>\n<li>\n<p><code>replace_pairs<\/code> \u2014 The replace_pairs parameter may be used instead of to and from, in which case it&#8217;s an array in the form array(&#8216;from&#8217; => &#8216;to&#8217;, &#8230;). <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>strtr()<\/code> Return Value<\/h3>\n<p>The PHP <code>strtr()<\/code> function returns the translated string.<\/p>\n<h3>PHP <code>strtr()<\/code> Working Examples<\/h3>\n<h4>1. strtr() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/In this form, strtr() does byte-by-byte translation\n\/\/Therefore, we are assuming a single-byte encoding here:\n$addr = strtr($addr, \"\u00e4\u00e5\u00f6\", \"aao\");\n?&gt;<\/code><\/pre>\n<h4>2. strtr() example with two arguments<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$trans = array(\"h\" =&gt; \"-\", \"hello\" =&gt; \"hi\", \"hi\" =&gt; \"hello\");\necho strtr(\"hi all, I said hello\", $trans);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">hello all, I said hi<\/code><\/pre>\n<h4>3. strtr() behavior comparison<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho strtr(\"baab\", \"ab\", \"01\"),\"\\n\";\n$trans = array(\"ab\" =&gt; \"01\");\necho strtr(\"baab\", $trans);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">1001\nba01<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: evan dot king<\/p>\n<pre><code class=\"lang-php\">Here's an important real-world example use-case for strtr where str_replace will not work or will introduce obscure bugs:\n&lt;?php\n$strTemplate = \"My name is :name, not :name2.\";\n$strParams = [\n  ':name' =&gt; 'Dave',\n  'Dave' =&gt; ':name2 or :password', \/\/ a wrench in the otherwise sensible input\n  ':name2' =&gt; 'Steve',\n  ':pass' =&gt; '7hf2348', \/\/ sensitive data that maybe shouldn't be here\n];\necho strtr($strTemplate, $strParams);\n\/\/ \"My name is Dave, not Steve.\"\necho str_replace(array_keys($strParams), array_values($strParams), $strTemplate);\n\/\/ \"My name is Steve or 7hf2348word, not Steve or 7hf2348word2.\"\n?&gt;\nAny time you're trying to template out a string and don't necessarily know what the replacement keys\/values will be (or fully understand the implications of and control their content and order), str_replace will introduce the potential to incorrectly match your keys because it does not expand the longest keys first.\nFurther, str_replace will replace in previous replacements, introducing potential for unintended nested expansions.  Doing so can put the wrong data into the \"sub-template\" or even give users a chance to provide input that exposes data (if they get to define some of the replacement strings).\nDon't support recursive expansion unless you need it and know it will be safe.  When you do support it, do so explicitly by repeating strtr calls until no more expansions are occurring or a sane iteration limit is reached, so that the results never implicitly depend on order of your replacement keys.  Also make certain that any user input will expanded in an isolated step after any sensitive data is already expanded into the output and no longer available as input.\nNote: using some character(s) around your keys to designate them also reduces the possibility of unintended mangling of output, whether maliciously triggered or otherwise.  Thus the use of a colon prefix in these examples, which you can easily enforce when accepting replacement input to your templating\/translation system.<\/code><\/pre>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">Since strtr (like PHP's other string functions) treats strings as a sequence of bytes, and since UTF-8 and other multibyte encodings use - by definition - more than one byte for at least some characters, the three-string form is likely to have problems. Use the associative array form to specify the mapping.\n&lt;?php\n\/\/ Assuming UTF-8\n$str = '\u00c4bc \u00c4bc'; \/\/ strtr() sees this as nine bytes (including two for each \u00c4)\necho strtr($str, '\u00c4', 'a'); \/\/ The second argument is equivalent to the string \"\\xc3\\x84\" so \"\\xc3\" gets replaced by \"a\" and the \"\\x84\" is ignored\necho strtr($str, array('\u00c4' =&gt; 'a')); \/\/ Works much better\n?&gt;<\/code><\/pre>\n<p>Contributed By: allixsenos<\/p>\n<pre><code class=\"lang-php\">Fixed \"normaliza\" functions written below to include Slavic Latin characters... also, it doesn't return lowercase any more (you can easily get that by applying strtolower yourself)...\nalso, renamed to normalize()\n&lt;?php\nfunction normalize ($string) {\n    $table = array(\n        '\u0160'=&gt;'S', '\u0161'=&gt;'s', '\u0110'=&gt;'Dj', '\u0111'=&gt;'dj', '\u017d'=&gt;'Z', '\u017e'=&gt;'z', '\u010c'=&gt;'C', '\u010d'=&gt;'c', '\u0106'=&gt;'C', '\u0107'=&gt;'c',\n        '\u00c0'=&gt;'A', '\u00c1'=&gt;'A', '\u00c2'=&gt;'A', '\u00c3'=&gt;'A', '\u00c4'=&gt;'A', '\u00c5'=&gt;'A', '\u00c6'=&gt;'A', '\u00c7'=&gt;'C', '\u00c8'=&gt;'E', '\u00c9'=&gt;'E',\n        '\u00ca'=&gt;'E', '\u00cb'=&gt;'E', '\u00cc'=&gt;'I', '\u00cd'=&gt;'I', '\u00ce'=&gt;'I', '\u00cf'=&gt;'I', '\u00d1'=&gt;'N', '\u00d2'=&gt;'O', '\u00d3'=&gt;'O', '\u00d4'=&gt;'O',\n        '\u00d5'=&gt;'O', '\u00d6'=&gt;'O', '\u00d8'=&gt;'O', '\u00d9'=&gt;'U', '\u00da'=&gt;'U', '\u00db'=&gt;'U', '\u00dc'=&gt;'U', '\u00dd'=&gt;'Y', '\u00de'=&gt;'B', '\u00df'=&gt;'Ss',\n        '\u00e0'=&gt;'a', '\u00e1'=&gt;'a', '\u00e2'=&gt;'a', '\u00e3'=&gt;'a', '\u00e4'=&gt;'a', '\u00e5'=&gt;'a', '\u00e6'=&gt;'a', '\u00e7'=&gt;'c', '\u00e8'=&gt;'e', '\u00e9'=&gt;'e',\n        '\u00ea'=&gt;'e', '\u00eb'=&gt;'e', '\u00ec'=&gt;'i', '\u00ed'=&gt;'i', '\u00ee'=&gt;'i', '\u00ef'=&gt;'i', '\u00f0'=&gt;'o', '\u00f1'=&gt;'n', '\u00f2'=&gt;'o', '\u00f3'=&gt;'o',\n        '\u00f4'=&gt;'o', '\u00f5'=&gt;'o', '\u00f6'=&gt;'o', '\u00f8'=&gt;'o', '\u00f9'=&gt;'u', '\u00fa'=&gt;'u', '\u00fb'=&gt;'u', '\u00fd'=&gt;'y', '\u00fd'=&gt;'y', '\u00fe'=&gt;'b',\n        '\u00ff'=&gt;'y', '\u0154'=&gt;'R', '\u0155'=&gt;'r',\n    );\n    \n    return strtr($string, $table);\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: dot dot dot dot dot alexander<\/p>\n<pre><code class=\"lang-php\">OK, I debugged the function (had some errors)\nHere it is:\nif(!function_exists(\"stritr\")){\n    function stritr($string, $one = NULL, $two = NULL){\n\/*\nstritr - case insensitive version of strtr\nAuthor: Alexander Peev\nPosted in PHP.NET\n*\/\n        if(  is_string( $one )  ){\n            $two = strval( $two );\n            $one = substr(  $one, 0, min( strlen($one), strlen($two) )  );\n            $two = substr(  $two, 0, min( strlen($one), strlen($two) )  );\n            $product = strtr(  $string, ( strtoupper($one) . strtolower($one) ), ( $two . $two )  );\n            return $product;\n        }\n        else if(  is_array( $one )  ){\n            $pos1 = 0;\n            $product = $string;\n            while(  count( $one ) &gt; 0  ){\n                $positions = array();\n                foreach(  $one as $from =&gt; $to  ){\n                    if(   (  $pos2 = stripos( $product, $from, $pos1 )  ) === FALSE   ){\n                        unset(  $one[ $from ]  );\n                    }\n                    else{\n                        $positions[ $from ] = $pos2;\n                    }\n                }\n                if(  count( $one ) &lt;= 0  )break;\n                $winner = min( $positions );\n                $key = array_search(  $winner, $positions  );\n                $product = (   substr(  $product, 0, $winner  ) . $one[$key] . substr(  $product, ( $winner + strlen($key) )  )   );\n                $pos1 = (  $winner + strlen( $one[$key] )  );\n            }\n            return $product;\n        }\n        else{\n            return $string;\n        }\n    }\/* endfunction stritr *\/\n}\/* endfunction exists stritr *\/<\/code><\/pre>\n<h2 id=\"substr\">PHP <code>substr()<\/code> Function<\/h2>\n<h3>What does <code>substr()<\/code> do?<\/h3>\n<p>The PHP <code><code>substr()<\/code><\/code> function will give you the portion of <code class=\"parameter\">string<\/code> specified by the <code class=\"parameter\">start<\/code> and <code class=\"parameter\">length<\/code> parameters.<\/p>\n<h3>PHP <code>substr()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> substr ( string $string , int $start [, int $length ] ) : string<\/code><\/pre>\n<h3>PHP <code>substr()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. Must be one character or longer. <\/p>\n<\/li>\n<li>\n<p><code>start<\/code> \u2014 If start is non-negative, the returned string will start at the start&#8217;th position in string, counting from zero. For instance, in the string &#8216;abcdef&#8217;, the character at position 0 is &#8216;a&#8217;, the character at position 2 is &#8216;c&#8217;, and so forth. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>substr()<\/code> Return Value<\/h3>\n<p>The PHP <code>substr()<\/code> function returns the extracted part of <code class=\"parameter\">string<\/code>; or <code>FALSE<\/code> on failure, or an empty string.<\/p>\n<h3>PHP <code>substr()<\/code> Working Examples<\/h3>\n<h4>1. Using a negative start<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$rest = substr(\"abcdef\", -1);    \/\/ returns \"f\"\n$rest = substr(\"abcdef\", -2);    \/\/ returns \"ef\"\n$rest = substr(\"abcdef\", -3, 1); \/\/ returns \"d\"\n?&gt;<\/code><\/pre>\n<h4>2. Using a negative length<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$rest = substr(\"abcdef\", 0, -1);  \/\/ returns \"abcde\"\n$rest = substr(\"abcdef\", 2, -1);  \/\/ returns \"cde\"\n$rest = substr(\"abcdef\", 4, -4);  \/\/ returns false\n$rest = substr(\"abcdef\", -3, -1); \/\/ returns \"de\"\n?&gt;<\/code><\/pre>\n<h4>3. Basic substr() usage<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho substr('abcdef', 1);     \/\/ bcdef\necho substr('abcdef', 1, 3);  \/\/ bcd\necho substr('abcdef', 0, 4);  \/\/ abcd\necho substr('abcdef', 0, 8);  \/\/ abcdef\necho substr('abcdef', -1, 1); \/\/ f\n\/\/ Accessing single characters in a string\n\/\/ can also be achieved using \"square brackets\"\n$string = 'abcdef';\necho $string[0];                 \/\/ a\necho $string[3];                 \/\/ d\necho $string[strlen($string)-1]; \/\/ f\n?&gt;<\/code><\/pre>\n<h4>4. substr() casting behaviour<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nclass apple {\n    public function __toString() {\n        return \"green\";\n    }\n}\necho \"1) \".var_export(substr(\"pear\", 0, 2), true).PHP_EOL;\necho \"2) \".var_export(substr(54321, 0, 2), true).PHP_EOL;\necho \"3) \".var_export(substr(new apple(), 0, 2), true).PHP_EOL;\necho \"4) \".var_export(substr(true, 0, 1), true).PHP_EOL;\necho \"5) \".var_export(substr(false, 0, 1), true).PHP_EOL;\necho \"6) \".var_export(substr(\"\", 0, 1), true).PHP_EOL;\necho \"7) \".var_export(substr(1.2e3, 0, 4), true).PHP_EOL;\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">1) 'pe'\n2) '54'\n3) 'gr'\n4) '1'\n5) ''\n6) ''\n7) '1200'<\/code><\/pre>\n<h3>Changelog for PHP substr()<\/code> Function<\/h3>\n<p><strong>7.0.0 \u2014 <\/strong> If <code class=\"parameter\">string<\/code> is equal to <code class=\"parameter\">start<\/code> characters long, an empty string will be returned. Prior to this version, <code>FALSE<\/code> was returned in this case. <\/p>\n<p><strong>5.2.2 &#8211; 5.2.6 \u2014 <\/strong> If the <code class=\"parameter\">start<\/code> parameter indicates the position of a negative truncation or beyond, false is returned. Other versions get the string from start. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Andreas Bur (andreas dot buro<\/p>\n<pre><code class=\"lang-php\">For getting a substring of UTF-8 characters, I highly recommend mb_substr\n&lt;?php\n        $utf8string = \"cake\u00e6\u00f8\u00e5\";\n        echo substr($utf8string,0,5);\n        \/\/ output cake#\n        echo mb_substr($utf8string,0,5,'UTF-8');\n        \/\/output cake\u00e6\n?&gt;<\/code><\/pre>\n<p>Contributed By: biohazard dot ge<\/p>\n<pre><code class=\"lang-php\">May be by following functions will be easier to extract the needed sub parts from a string:\n&lt;?php\nafter ('@', 'biohazard@online.ge');\n\/\/returns 'online.ge'\n\/\/from the first occurrence of '@'\nbefore ('@', 'biohazard@online.ge');\n\/\/returns 'biohazard'\n\/\/from the first occurrence of '@'\nbetween ('@', '.', 'biohazard@online.ge');\n\/\/returns 'online'\n\/\/from the first occurrence of '@'\nafter_last ('[', 'sin[90]*cos[180]');\n\/\/returns '180]'\n\/\/from the last occurrence of '['\nbefore_last ('[', 'sin[90]*cos[180]');\n\/\/returns 'sin[90]*cos['\n\/\/from the last occurrence of '['\nbetween_last ('[', ']', 'sin[90]*cos[180]');\n\/\/returns '180'\n\/\/from the last occurrence of '['\n?&gt;\nhere comes the source:\n&lt;?php\n    function after ($this, $inthat)\n    {\n        if (!is_bool(strpos($inthat, $this)))\n        return substr($inthat, strpos($inthat,$this)+strlen($this));\n    };\n    function after_last ($this, $inthat)\n    {\n        if (!is_bool(strrevpos($inthat, $this)))\n        return substr($inthat, strrevpos($inthat, $this)+strlen($this));\n    };\n    function before ($this, $inthat)\n    {\n        return substr($inthat, 0, strpos($inthat, $this));\n    };\n    function before_last ($this, $inthat)\n    {\n        return substr($inthat, 0, strrevpos($inthat, $this));\n    };\n    function between ($this, $that, $inthat)\n    {\n        return before ($that, after($this, $inthat));\n    };\n    function between_last ($this, $that, $inthat)\n    {\n     return after_last($this, before_last($that, $inthat));\n    };\n\/\/ use strrevpos function in case your php version does not include it\nfunction strrevpos($instr, $needle)\n{\n    $rev_pos = strpos (strrev($instr), strrev($needle));\n    if ($rev_pos===false) return false;\n    else return strlen($instr) - $rev_pos - strlen($needle);\n};\n?&gt;<\/code><\/pre>\n<p>Contributed By: pugazhenthi k<\/p>\n<pre><code class=\"lang-php\">&lt;?Php \n### SUB STRING  BY WORD USING substr() and strpos()  #####\n### THIS SCRIPT WILL RETURN PART OF STRING  WITHOUT WORD BREAK ###\n$description = \u2018your description here your description here your description here your description here your description here your description here your description hereyour description here your description here\u2019  \/\/ your description here .\n$no_letter = 30 ;\nif(strlen($desctiption) &gt; 30 )\n{\n     echo substr($description,0,strpos($description,\u2019 \u2018,30));             \/\/strpos to find \u2018 \u2018 after 30 characters.\n}\nelse {\n     echo $description;\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"substr_compare\">PHP <code>substr_compare()<\/code> Function<\/h2>\n<h3>What does <code>substr_compare()<\/code> do?<\/h3>\n<p>The PHP <code><code>substr_compare()<\/code><\/code> function will binary safe comparison of two strings from an offset, up to length characters.<\/p>\n<h3>PHP <code>substr_compare()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> substr_compare ( string $main_str , string $str , int $offset [, int $length [, bool $case_insensitivity = FALSE ]] ) : int<\/code><\/pre>\n<h3>PHP <code>substr_compare()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>main_str<\/code> \u2014 The main string being compared. <\/p>\n<\/li>\n<li>\n<p><code>str<\/code> \u2014 The secondary string being compared. <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 The start position for the comparison. If negative, it starts counting from the end of the string. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 The length of the comparison. The default value is the largest of the length of the str compared to the length of main_str minus the offset. <\/p>\n<\/li>\n<li>\n<p><code>case_insensitivity<\/code> \u2014 If case_insensitivity is TRUE, comparison is case insensitive. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>substr_compare()<\/code> Return Value<\/h3>\n<p>The PHP <code>substr_compare()<\/code> function returns &lt; 0 if <code class=\"parameter\">main_str<\/code> from position <code class=\"parameter\">offset<\/code> is less than <code class=\"parameter\">str<\/code>, &gt; 0 if it is greater than <code class=\"parameter\">str<\/code>, and 0 if they are equal. If <code class=\"parameter\">offset<\/code> is equal to (prior to PHP 7.2.18, 7.3.5) or greater than the length of <code class=\"parameter\">main_str<\/code>, or the <code class=\"parameter\">length<\/code> is set and is less than 0, (or, prior to PHP 5.5.11, less than 1) <code>substr_compare()<\/code> prints a warning and return <code>FALSE<\/code>.<\/p>\n<h3>PHP <code>substr_compare()<\/code> Working Examples<\/h3>\n<h4>1. A substr_compare() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho substr_compare(\"abcde\", \"bc\", 1, 2); \/\/ 0\necho substr_compare(\"abcde\", \"de\", -2, 2); \/\/ 0\necho substr_compare(\"abcde\", \"bcg\", 1, 2); \/\/ 0\necho substr_compare(\"abcde\", \"BC\", 1, 2, true); \/\/ 0\necho substr_compare(\"abcde\", \"bc\", 1, 3); \/\/ 1\necho substr_compare(\"abcde\", \"cd\", 1, 2); \/\/ -1\necho substr_compare(\"abcde\", \"abc\", 5, 1); \/\/ warning\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP substr_compare()<\/code> Function<\/h3>\n<p><strong>7.2.18, 7.3.5 \u2014 <\/strong> <code class=\"parameter\">offset<\/code> may now be equal to the length of <code class=\"parameter\">main_str<\/code>. <\/p>\n<p><strong>5.5.11 \u2014 <\/strong> <code class=\"parameter\">length<\/code> may now be 0. <\/p>\n<p><strong>5.1.0 \u2014 <\/strong> Added the possibility to use a negative <code class=\"parameter\">offset<\/code>. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jimmetry<\/p>\n<pre><code class=\"lang-php\">When you came to this page, you may have been looking for something a little simpler: A function that can check if a small string exists within a larger string starting at a particular index. Using substr_compare() for this can leave your code messy, because you need to check that your string is long enough (to avoid the warning), manually specify the length of the short string, and like many of the string functions, perform an integer comparison to answer a true\/false question.\nI put together a simple function to return true if $str exists within $mainStr. If $loc is specified, the $str must begin at that index. If not, the entire $mainStr will be searched.\n&lt;?php\nfunction contains_substr($mainStr, $str, $loc = false) {\n    if ($loc === false) return (strpos($mainStr, $str) !== false);\n    if (strlen($mainStr) &lt; strlen($str)) return false;\n    if (($loc + strlen($str)) &gt; strlen($mainStr)) return false;\n    return (strcmp(substr($mainStr, $loc, strlen($str)), $str) == 0);\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"substr_count\">PHP <code>substr_count()<\/code> Function<\/h2>\n<h3>What does <code>substr_count()<\/code> do?<\/h3>\n<p>The PHP <code><code>substr_count()<\/code><\/code> function will count the number of substring occurrences.<\/p>\n<h3>PHP <code>substr_count()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) : int<\/code><\/pre>\n<h3>PHP <code>substr_count()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>haystack<\/code> \u2014 The string to search in <\/p>\n<\/li>\n<li>\n<p><code>needle<\/code> \u2014 The substring to search for <\/p>\n<\/li>\n<li>\n<p><code>offset<\/code> \u2014 The offset where to start counting. If the offset is negative, counting starts from the end of the string. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is greater than the haystack length. A negative length counts from the end of haystack. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>substr_count()<\/code> Return Value<\/h3>\n<p>The PHP <code>substr_count()<\/code> function returns an integer.<\/p>\n<h3>PHP <code>substr_count()<\/code> Working Examples<\/h3>\n<h4>1. A substr_count() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = 'This is a test';\necho strlen($text); \/\/ 14\necho substr_count($text, 'is'); \/\/ 2\n\/\/ the string is reduced to 's is a test', so it prints 1\necho substr_count($text, 'is', 3);\n\/\/ the text is reduced to 's i', so it prints 0\necho substr_count($text, 'is', 3, 3);\n\/\/ generates a warning because 5+10 &gt; 14\necho substr_count($text, 'is', 5, 10);\n\/\/ prints only 1, because it doesn't count overlapped substrings\n$text2 = 'gcdgcdgcd';\necho substr_count($text2, 'gcdgcd');\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP substr_count()<\/code> Function<\/h3>\n<p><strong>7.1.0 \u2014 <\/strong> Support for negative <code class=\"parameter\">offset<\/code>s and <code class=\"parameter\">length<\/code>s has been added. <code class=\"parameter\">length<\/code> may also be 0 now. <\/p>\n<p><strong>5.1.0 \u2014 <\/strong> Added the <code class=\"parameter\">offset<\/code> and the <code class=\"parameter\">length<\/code> parameters <\/p>\n<h3>Important Points about PHP <code>substr_count()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> This function doesn&#8217;t count overlapped substrings. See the example below! <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: tuxedobob<\/p>\n<pre><code class=\"lang-php\">It's worth noting this function is surprisingly fast. I first ran it against a ~500KB string on our web server. It found 6 occurrences of the needle I was looking for in 0.0000 seconds. Yes, it ran faster than microtime() could measure.\nLooking to give it a challenge, I then ran it on a Mac laptop from 2010 against a 120.5MB string. For one test needle, it found 2385 occurrences in 0.0266 seconds. Another test needs found 290 occurrences in 0.114 seconds.\nLong story short, if you're wondering whether this function is slowing down your script, the answer is probably not.<\/code><\/pre>\n<h2 id=\"substr_replace\">PHP <code>substr_replace()<\/code> Function<\/h2>\n<h3>What does <code>substr_replace()<\/code> do?<\/h3>\n<p>The PHP <code><code>substr_replace()<\/code><\/code> function will replace text within a portion of a string.<\/p>\n<h3>PHP <code>substr_replace()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] ) : mixed<\/code><\/pre>\n<h3>PHP <code>substr_replace()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>string<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>replacement<\/code> \u2014 The replacement string. <\/p>\n<\/li>\n<li>\n<p><code>start<\/code> \u2014 If start is non-negative, the replacing will begin at the start&#8217;th offset into string. <\/p>\n<\/li>\n<li>\n<p><code>length<\/code> \u2014 If given and is positive, it represents the length of the portion of string which is to be replaced. If it is negative, it represents the number of characters from the end of string at which to stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the end of string. Of course, if length is zero then this function will have the effect of inserting replacement into string at the given start offset. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>substr_replace()<\/code> Return Value<\/h3>\n<p>The PHP <code>substr_replace()<\/code> function returns d. If <code class=\"parameter\">string<\/code> is an array then array is returned.<\/p>\n<h3>PHP <code>substr_replace()<\/code> Working Examples<\/h3>\n<h4>1. Simple substr_replace() examples<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$var = 'ABCDEFGH:\/MNRPQR\/';\necho \"Original: $var&lt;hr \/&gt;\\n\";\n\/* These two examples replace all of $var with 'bob'. *\/\necho substr_replace($var, 'bob', 0) . \"&lt;br \/&gt;\\n\";\necho substr_replace($var, 'bob', 0, strlen($var)) . \"&lt;br \/&gt;\\n\";\n\/* Insert 'bob' right at the beginning of $var. *\/\necho substr_replace($var, 'bob', 0, 0) . \"&lt;br \/&gt;\\n\";\n\/* These next two replace 'MNRPQR' in $var with 'bob'. *\/\necho substr_replace($var, 'bob', 10, -1) . \"&lt;br \/&gt;\\n\";\necho substr_replace($var, 'bob', -7, -1) . \"&lt;br \/&gt;\\n\";\n\/* Delete 'MNRPQR' from $var. *\/\necho substr_replace($var, '', 10, -1) . \"&lt;br \/&gt;\\n\";\n?&gt;<\/code><\/pre>\n<h4>2. Using substr_replace() to replace multiple strings at once <\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$input = array('A: XXX', 'B: XXX', 'C: XXX');\n\/\/ A simple case: replace XXX in each string with YYY.\necho implode('; ', substr_replace($input, 'YYY', 3, 3)).\"\\n\";\n\/\/ A more complicated case where each replacement is different.\n$replace = array('AAA', 'BBB', 'CCC');\necho implode('; ', substr_replace($input, $replace, 3, 3)).\"\\n\";\n\/\/ Replace a different number of characters each time.\n$length = array(1, 2, 3);\necho implode('; ', substr_replace($input, $replace, 3, $length)).\"\\n\";\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">A: YYY; B: YYY; C: YYY\nA: AAA; B: BBB; C: CCC\nA: AAAXX; B: BBBX; C: CCC<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: elloromtz<\/p>\n<pre><code class=\"lang-php\">It's worth noting that when start and length are both negative -and- the length is less than or equal to start, the length will have the effect of being set as 0. \n \n&lt;?php \nsubstr_replace('eggs','x',-1,-1); \/\/eggxs \nsubstr_replace('eggs','x',-1,-2); \/\/eggxs \nsubstr_replace('eggs','x',-1,-2); \/\/eggxs \n?&gt; \n \nSame as: \n&lt;?php \nsubstr_replace('eggs','x',-1,0); \/\/eggxs \n?&gt; \n \n&lt;?php \nsubstr_replace('huevos','x',-2,-2); \/\/huevxos \nsubstr_replace('huevos','x',-2,-3); \/\/huevxos \nsubstr_replace('huevos','x',-2,-3); \/\/huevxos \n?&gt; \n \nSame as: \n&lt;?php \nsubstr_replace('huevos','x',-2,0); \/\/huevxos \n?&gt; \n \nAnother note, if length is negative and start offsets the same position as length, length (yet again) will have the effect as being set as 0. (Of course, as mentioned in the manual, when length is negative it actually represents the position before it) \n \n&lt;?php \nsubstr_replace('abcd', 'x', 0, -4); \/\/xabcd \n?&gt; \n \nSame as: \n&lt;?php \nsubstr_replace('abcd','x',0,0); \/\/xabcd \n?&gt; \n \n&lt;?php \nsubstr_replace('abcd', 'x', 1, -3); \/\/axbcd \n?&gt; \n \nSame as: \n&lt;?php \nsubstr_replace('abcd', 'x', 1, 0); \/\/axbcd \n?&gt;<\/code><\/pre>\n<h2 id=\"trim\">PHP <code>trim()<\/code> Function<\/h2>\n<h3>What does <code>trim()<\/code> do?<\/h3>\n<p>The PHP <code><code>trim()<\/code><\/code> function will strip whitespace (or other characters) from the beginning and end of a string.<\/p>\n<h3>PHP <code>trim()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> trim ( string $str [, string $character_mask = \" \\t\\n\\r\\0\\x0B\" ] ) : string<\/code><\/pre>\n<h3>PHP <code>trim()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The string that will be trimmed. <\/p>\n<\/li>\n<li>\n<p><code>character_mask<\/code> \u2014 Optionally, the stripped characters can also be specified using the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>trim()<\/code> Return Value<\/h3>\n<p>The PHP <code>trim()<\/code> function returns the trimmed string.<\/p>\n<h3>PHP <code>trim()<\/code> Working Examples<\/h3>\n<h4>1. Usage example of trim()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text   = \"\\t\\tThese are a few words :) ...  \";\n$binary = \"\\x09Example string\\x0A\";\n$hello  = \"Hello World\";\nvar_dump($text, $binary, $hello);\nprint \"\\n\";\n$trimmed = trim($text);\nvar_dump($trimmed);\n$trimmed = trim($text, \" \\t.\");\nvar_dump($trimmed);\n$trimmed = trim($hello, \"Hdle\");\nvar_dump($trimmed);\n$trimmed = trim($hello, 'HdWr');\nvar_dump($trimmed);\n\/\/ trim the ASCII control characters at the beginning and end of $binary\n\/\/ (from 0 to 31 inclusive)\n$clean = trim($binary, \"\\x00..\\x1F\");\nvar_dump($clean);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">string(32) \" These are a few words :) ... \"\nstring(16) \" Example string\n\"\nstring(11) \"Hello World\"\nstring(28) \"These are a few words :) ...\"\nstring(24) \"These are a few words :)\"\nstring(5) \"o Wor\"\nstring(9) \"ello Worl\"\nstring(14) \"Example string\"<\/code><\/pre>\n<h4>2. Trimming array values with trim()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nfunction trim_value(&amp;$value) \n{ \n    $value = trim($value); \n}\n$fruit = array('apple','banana ', ' cranberry ');\nvar_dump($fruit);\narray_walk($fruit, 'trim_value');\nvar_dump($fruit);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">array(3) {\n [0]=&gt;\n string(5) \"apple\"\n [1]=&gt;\n string(7) \"banana \"\n [2]=&gt;\n string(11) \" cranberry \"\n}\narray(3) {\n [0]=&gt;\n string(5) \"apple\"\n [1]=&gt;\n string(6) \"banana\"\n [2]=&gt;\n string(9) \"cranberry\"\n}<\/code><\/pre>\n<h3>Important Points about PHP <code>trim()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> Because <code>trim()<\/code> trims characters from the beginning and end of a string, it may be confusing when characters are (or are not) removed from the middle. <strong>trim(&#8216;abc&#8217;, &#8216;bad&#8217;)<\/strong> removes both &#8216;a&#8217; and &#8216;b&#8217; because it trims &#8216;a&#8217; thus moving &#8216;b&#8217; to the beginning to also be trimmed. So, this is why it &#8220;works&#8221; whereas <strong>trim(&#8216;abc&#8217;, &#8216;b&#8217;)<\/strong> seemingly does not. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: Piopier<\/p>\n<pre><code class=\"lang-php\">It may be useful to know that trim() returns an empty string when the argument is an unset\/null variable.<\/code><\/pre>\n<p>Contributed By: aalhad<\/p>\n<pre><code class=\"lang-php\">When specifying the character mask, \nmake sure that you use double quotes\n&lt;?php\n  $hello = \" \n      Hello World   \"; \/\/here is a string with some trailing and leading whitespace\n  $trimmed_correct   = trim($hello, \" \\t\\n\\r\"); \/\/&lt;--------OKAY\n  $trimmed_incorrect = trim($hello, ' \\t\\n\\r'); \/\/&lt;--------NOT AS EXPECTED\n  print(\"----------------------------\");\n  print(\"TRIMMED OK:\".PHP_EOL);\n  print_r($trimmed_correct.PHP_EOL);\n  print(\"----------------------------\");\n  print(\"TRIMMING NOT OK:\".PHP_EOL);\n  print_r($trimmed_incorrect.PHP_EOL);\n  print(\"----------------------------\".PHP_EOL);\n?&gt;\nHere is the output:\n----------------------------TRIMMED OK:\nHello World\n----------------------------TRIMMING NOT OK:\n      Hello World\n----------------------------<\/code><\/pre>\n<p>Contributed By: ludko2<\/p>\n<pre><code class=\"lang-php\">Non-breaking spaces can be troublesome with trim: \n \n&lt;?php \n\/\/ turn some HTML with non-breaking spaces into a \"normal\" string \n$myHTML = \"&amp;nbsp;abc\"; \n$converted = strtr($myHTML, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES))); \n \n\/\/ this WILL NOT work as expected \n\/\/ $converted will still appear as \" abc\" in view source \n\/\/ (but not in od -x) \n$converted = trim($converted); \n \n\/\/ &amp;nbsp; are translated to 0xA0, so use: \n$converted = trim($converted, \"\\xA0\"); \/\/ &lt;- THIS DOES NOT WORK \n \n\/\/ EDITED&gt;&gt; \n\/\/ UTF encodes it as chr(0xC2).chr(0xA0) \n$converted = trim($converted,chr(0xC2).chr(0xA0)); \/\/ should work \n \n\/\/ PS: Thanks to John for saving my sanity! \n?&gt;<\/code><\/pre>\n<p>Contributed By: jubi<\/p>\n<pre><code class=\"lang-php\">To remove multiple occurences of whitespace characters in a string an convert them all into single spaces, use this:\n&lt;?\n$text = preg_replace('\/\\s+\/', ' ', $text);\n?&gt;\n------------\nJUBI\nhttp:\/\/www.jubi.buum.pl<\/code><\/pre>\n<h2 id=\"ucfirst\">PHP <code>ucfirst()<\/code> Function<\/h2>\n<h3>What does <code>ucfirst()<\/code> do?<\/h3>\n<p>The PHP <code><code>ucfirst()<\/code><\/code> function will make a string&#8217;s first character uppercase.<\/p>\n<h3>PHP <code>ucfirst()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> ucfirst ( string $str ) : string<\/code><\/pre>\n<h3>PHP <code>ucfirst()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>ucfirst()<\/code> Return Value<\/h3>\n<p>The PHP <code>ucfirst()<\/code> function returns the resulting string.<\/p>\n<h3>PHP <code>ucfirst()<\/code> Working Examples<\/h3>\n<h4>1. ucfirst() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$foo = 'hello world!';\n$foo = ucfirst($foo);             \/\/ Hello world!\n$bar = 'HELLO WORLD!';\n$bar = ucfirst($bar);             \/\/ HELLO WORLD!\n$bar = ucfirst(strtolower($bar)); \/\/ Hello world!\n?&gt;<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: plemieux<\/p>\n<pre><code class=\"lang-php\">Simple multi-bytes ucfirst():\n&lt;?php\nfunction my_mb_ucfirst($str) {\n    $fc = mb_strtoupper(mb_substr($str, 0, 1));\n    return $fc.mb_substr($str, 1);\n}\n?&gt;<\/code><\/pre>\n<p>Contributed By: prokur.net &#8211; there is my email<\/p>\n<pre><code class=\"lang-php\">I believe that mb_ucfirst will be soon added in PHP, but for now this could be useful\n&lt;?php\nif (!function_exists('mb_ucfirst') &amp;&amp; function_exists('mb_substr')) {\n    function mb_ucfirst($string) {\n        $string = mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);\n        return $string;\n    }\n}\n?&gt;\nit also check is mb support enabled or not<\/code><\/pre>\n<p>Contributed By: mattalexxpub<\/p>\n<pre><code class=\"lang-php\">This is what I use for converting strings to sentence case: \n \n&lt;?php \nfunction sentence_case($string) { \n    $sentences = preg_split('\/([.?!]+)\/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); \n    $new_string = ''; \n    foreach ($sentences as $key =&gt; $sentence) { \n        $new_string .= ($key &amp; 1) == 0? \n            ucfirst(strtolower(trim($sentence))) : \n            $sentence.' '; \n    } \n    return trim($new_string); \n} \n \nprint sentence_case('HMM. WOW! WHAT?'); \n \n\/\/ Outputs: \"Hmm. Wow! What?\" \n?&gt;<\/code><\/pre>\n<h2 id=\"ucwords\">PHP <code>ucwords()<\/code> Function<\/h2>\n<h3>What does <code>ucwords()<\/code> do?<\/h3>\n<p>The PHP <code><code>ucwords()<\/code><\/code> function will uppercase the first character of each word in a string.<\/p>\n<h3>PHP <code>ucwords()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> ucwords ( string $str [, string $delimiters = \" \\t\\r\\n\\f\\v\" ] ) : string<\/code><\/pre>\n<h3>PHP <code>ucwords()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>delimiters<\/code> \u2014 The optional delimiters contains the word separator characters. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>ucwords()<\/code> Return Value<\/h3>\n<p>The PHP <code>ucwords()<\/code> function returns the modified string.<\/p>\n<h3>PHP <code>ucwords()<\/code> Working Examples<\/h3>\n<h4>1. ucwords() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$foo = 'hello world!';\n$foo = ucwords($foo);             \/\/ Hello World!\n$bar = 'HELLO WORLD!';\n$bar = ucwords($bar);             \/\/ HELLO WORLD!\n$bar = ucwords(strtolower($bar)); \/\/ Hello World!\n?&gt;<\/code><\/pre>\n<h4>2. ucwords() example with custom delimiter<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$foo = 'hello|world!';\n$bar = ucwords($foo);             \/\/ Hello|world!\n$baz = ucwords($foo, \"|\");        \/\/ Hello|World!\n?&gt;<\/code><\/pre>\n<h3>Changelog for PHP ucwords()<\/code> Function<\/h3>\n<p><strong>5.4.32, 5.5.16 \u2014 <\/strong> Added the <code class=\"parameter\">delimiters<\/code> parameter. <\/p>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: jmarois<\/p>\n<pre><code class=\"lang-php\">My quick and dirty ucname (Upper Case Name) function.\n&lt;?php\n\/\/FUNCTION\nfunction ucname($string) {\n    $string =ucwords(strtolower($string));\n    foreach (array('-', '\\'') as $delimiter) {\n      if (strpos($string, $delimiter)!==false) {\n        $string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));\n      }\n    }\n    return $string;\n}\n?&gt;\n&lt;?php\n\/\/TEST\n$names =array(\n  'JEAN-LUC PICARD',\n  'MILES O\\'BRIEN',\n  'WILLIAM RIKER',\n  'geordi la forge',\n  'bEvErly CRuSHeR'\n);\nforeach ($names as $name) { print ucname(\"{$name}\\n\"); }\n\/\/PRINTS:\n\/*\nJean-Luc Picard\nMiles O'Brien\nWilliam Riker\nGeordi La Forge\nBeverly Crusher\n*\/\n?&gt;\nYou can add more delimiters in the for-each loop array if you want to handle more characters.<\/code><\/pre>\n<p>Contributed By: antoniomax<\/p>\n<pre><code class=\"lang-php\">Para formatar nomes em pt-br:\n&lt;?php\n    function titleCase($string, $delimiters = array(\" \", \"-\", \".\", \"'\", \"O'\", \"Mc\"), $exceptions = array(\"de\", \"da\", \"dos\", \"das\", \"do\", \"I\", \"II\", \"III\", \"IV\", \"V\", \"VI\"))\n    {\n        \/*\n         * Exceptions in lower case are words you don't want converted\n         * Exceptions all in upper case are any words you don't want converted to title case\n         *   but should be converted to upper case, e.g.:\n         *   king henry viii or king henry Viii should be King Henry VIII\n         *\/\n        $string = mb_convert_case($string, MB_CASE_TITLE, \"UTF-8\");\n        foreach ($delimiters as $dlnr =&gt; $delimiter) {\n            $words = explode($delimiter, $string);\n            $newwords = array();\n            foreach ($words as $wordnr =&gt; $word) {\n                if (in_array(mb_strtoupper($word, \"UTF-8\"), $exceptions)) {\n                    \/\/ check exceptions list for any words that should be in upper case\n                    $word = mb_strtoupper($word, \"UTF-8\");\n                } elseif (in_array(mb_strtolower($word, \"UTF-8\"), $exceptions)) {\n                    \/\/ check exceptions list for any words that should be in upper case\n                    $word = mb_strtolower($word, \"UTF-8\");\n                } elseif (!in_array($word, $exceptions)) {\n                    \/\/ convert to uppercase (non-utf8 only)\n                    $word = ucfirst($word);\n                }\n                array_push($newwords, $word);\n            }\n            $string = join($delimiter, $newwords);\n       }\/\/foreach\n       return $string;\n    }\n?&gt;\nUsage:\n&lt;?php\n    $s = 'S\u00c3O JO\u00c3O DOS SANTOS';\n    $v = titleCase($s); \/\/ 'S\u00e3o Jo\u00e3o dos Santos' \n?&gt;<\/code><\/pre>\n<p>Contributed By: robert<\/p>\n<pre><code class=\"lang-php\">Some recipes for switching between underscore and camelcase naming: \n \n&lt;?php \n\/\/ underscored to upper-camelcase \n\/\/ e.g. \"this_method_name\" -&gt; \"ThisMethodName\" \npreg_replace('\/(?:^|_)(.?)\/e',\"strtoupper('$1')\",$string); \n \n\/\/ underscored to lower-camelcase \n\/\/ e.g. \"this_method_name\" -&gt; \"thisMethodName\" \npreg_replace('\/_(.?)\/e',\"strtoupper('$1')\",$string); \n \n\/\/ camelcase (lower or upper) to underscored \n\/\/ e.g. \"thisMethodName\" -&gt; \"this_method_name\" \n\/\/ e.g. \"ThisMethodName\" -&gt; \"this_method_name\" \nstrtolower(preg_replace('\/([^A-Z])([A-Z])\/', \"$1_$2\", $string)); \n?&gt; \n \nOf course these aren't 100% symmetric.  For example... \n  * this_is_a_string -&gt; ThisIsAString -&gt; this_is_astring \n  * GetURLForString -&gt; get_urlfor_string -&gt; GetUrlforString<\/code><\/pre>\n<p>Contributed By: Luca Borrione luca -a email -d c_o_m<\/p>\n<pre><code class=\"lang-php\">Features: \n- multi byte compatible \n- handles multiple delimiters \n \n&lt;?php \nfunction ucwords_specific ($string, $delimiters = '', $encoding = NULL) \n{ \n    if ($encoding === NULL) { $encoding = mb_internal_encoding();} \n \n    if (is_string($delimiters)) \n    { \n        $delimiters =  str_split( str_replace(' ', '', $delimiters)); \n    } \n \n    $delimiters_pattern1 = array(); \n    $delimiters_replace1 = array(); \n    $delimiters_pattern2 = array(); \n    $delimiters_replace2 = array(); \n    foreach ($delimiters as $delimiter) \n    { \n        $uniqid = uniqid(); \n        $delimiters_pattern1[]   = '\/'. preg_quote($delimiter) .'\/'; \n        $delimiters_replace1[]   = $delimiter.$uniqid.' '; \n        $delimiters_pattern2[]   = '\/'. preg_quote($delimiter.$uniqid.' ') .'\/'; \n        $delimiters_replace2[]   = $delimiter; \n    } \n \n    \/\/ $return_string = mb_strtolower($string, $encoding); \n    $return_string = $string; \n    $return_string = preg_replace($delimiters_pattern1, $delimiters_replace1, $return_string); \n \n    $words = explode(' ', $return_string); \n \n    foreach ($words as $index =&gt; $word) \n    { \n        $words[$index] = mb_strtoupper(mb_substr($word, 0, 1, $encoding), $encoding).mb_substr($word, 1, mb_strlen($word, $encoding), $encoding); \n    } \n \n    $return_string = implode(' ', $words); \n \n    $return_string = preg_replace($delimiters_pattern2, $delimiters_replace2, $return_string); \n \n    return $return_string; \n} \n?&gt; \n \nParams: \n1. string: The string being converted \n2. delimiters: a string with all wanted delimiters written one after the other e.g. \"-'\" \n3. encoding: Is the character encoding. If it is omitted, the internal character encoding value will be used. \n \nExample Usage: \n&lt;?php \nmb_internal_encoding('UTF-8'); \n$string = \"JEAN-PAUL d'artagnan \u015f\u0160-\u00f2\u00c0-\u00e9\u00cc hello - world\"; \necho ucwords_specific( mb_strtolower($string, 'UTF-8'), \"-'\"); \n?&gt; \n \nOutput: \nJean-Paul D'Artagnan \u015e\u0161-\u00d2\u00e0-\u00c9\u00ec Hello - World<\/code><\/pre>\n<h2 id=\"vfprintf\">PHP <code>vfprintf()<\/code> Function<\/h2>\n<h3>What does <code>vfprintf()<\/code> do?<\/h3>\n<p>The PHP <code><code>vfprintf()<\/code><\/code> function will write a string produced according to <code class=\"parameter\">format<\/code> to the stream resource specified by <code class=\"parameter\">handle<\/code>.<\/p>\n<h3>PHP <code>vfprintf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> vfprintf ( resource $handle , string $format , array $args ) : int<\/code><\/pre>\n<h3>PHP <code>vfprintf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>handle<\/code> \u2014 <\/p>\n<\/li>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>args<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>vfprintf()<\/code> Return Value<\/h3>\n<p>The PHP <code>vfprintf()<\/code> function returns the length of the outputted string.<\/p>\n<h3>PHP <code>vfprintf()<\/code> Working Examples<\/h3>\n<h4>1. vfprintf(): zero-padded integers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nif (!($fp = fopen('date.txt', 'w')))\n    return;\nvfprintf($fp, \"%04d-%02d-%02d\", array($year, $month, $day));\n\/\/ will write the formatted ISO date to date.txt\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>vfprintf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"vprintf\">PHP <code>vprintf()<\/code> Function<\/h2>\n<h3>What does <code>vprintf()<\/code> do?<\/h3>\n<p>The PHP <code><code>vprintf()<\/code><\/code> function will display array values as a formatted string according to <code class=\"parameter\">format<\/code> (which is described in the documentation for <code>sprintf()<\/code>).<\/p>\n<h3>PHP <code>vprintf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> vprintf ( string $format , array $args ) : int<\/code><\/pre>\n<h3>PHP <code>vprintf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>args<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>vprintf()<\/code> Return Value<\/h3>\n<p>The PHP <code>vprintf()<\/code> function returns the length of the outputted string.<\/p>\n<h3>PHP <code>vprintf()<\/code> Working Examples<\/h3>\n<h4>1. vprintf(): zero-padded integers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nvprintf(\"%04d-%02d-%02d\", explode('-', '1988-8-1'));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">1988-08-01<\/code><\/pre>\n<h3>Important Points about PHP <code>vprintf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"vsprintf\">PHP <code>vsprintf()<\/code> Function<\/h2>\n<h3>What does <code>vsprintf()<\/code> do?<\/h3>\n<p>The PHP <code><code>vsprintf()<\/code><\/code> function will operates as <code>sprintf()<\/code> but accepts an array of arguments, rather than a variable number of arguments.<\/p>\n<h3>PHP <code>vsprintf()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> vsprintf ( string $format , array $args ) : string<\/code><\/pre>\n<h3>PHP <code>vsprintf()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>format<\/code> \u2014 The format string is composed of zero or more directives: ordinary characters (excluding %) that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. <\/p>\n<\/li>\n<li>\n<p><code>args<\/code> \u2014 <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>vsprintf()<\/code> Return Value<\/h3>\n<p>The PHP <code>vsprintf()<\/code> function returns <\/p>\n<h3>PHP <code>vsprintf()<\/code> Working Examples<\/h3>\n<h4>1. vsprintf(): zero-padded integers<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nprint vsprintf(\"%04d-%02d-%02d\", explode('-', '1988-8-1'));\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">1988-08-01<\/code><\/pre>\n<h3>Important Points about PHP <code>vsprintf()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> The <strong>c<\/strong> type specifier ignores padding and width <\/p>\n<\/li>\n<li>\n<p> Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: <\/p>\n<pre><code class=\"lang-php\">Instead of inventing own functions in case you'd like to use array keys as placeholder names and replace corresponding array values in a string, just use the str_replace:\n$string = 'Hello %name!';\n$data = array(\n  '%name' =&gt; 'John'\n);\n$greeting = str_replace(array_keys($data), array_values($data), $string);<\/code><\/pre>\n<p>Contributed By: Josef Kufner<\/p>\n<pre><code class=\"lang-php\">&lt;?php \n\/** \n * Like vsprintf, but accepts $args keys instead of order index. \n * Both numeric and strings matching \/[a-zA-Z0-9_-]+\/ are allowed. \n * \n * Example: vskprintf('y = %y$d, x = %x$1.1f', array('x' =&gt; 1, 'y' =&gt; 2)) \n * Result:  'y = 2, x = 1.0' \n * \n * $args also can be object, then it's properties are retrieved \n * using get_object_vars(). \n * \n * '%s' without argument name works fine too. Everything vsprintf() can do \n * is supported. \n * \n * @author Josef Kufner &lt;jkufner(at)gmail.com&gt; \n *\/ \nfunction vksprintf($str, $args) \n{ \n    if (is_object($args)) { \n        $args = get_object_vars($args); \n    } \n    $map = array_flip(array_keys($args)); \n    $new_str = preg_replace_callback('\/(^|[^%])%([a-zA-Z0-9_-]+)\\$\/', \n            function($m) use ($map) { return $m[1].'%'.($map[$m[2]] + 1).'$'; }, \n            $str); \n    return vsprintf($new_str, $args); \n} \n?&gt;<\/code><\/pre>\n<h2 id=\"wordwrap\">PHP <code>wordwrap()<\/code> Function<\/h2>\n<h3>What does <code>wordwrap()<\/code> do?<\/h3>\n<p>The PHP <code><code>wordwrap()<\/code><\/code> function will wraps a string to a given number of characters.<\/p>\n<h3>PHP <code>wordwrap()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> wordwrap ( string $str [, int $width = 75 [, string $break = \"\\n\" [, bool $cut = FALSE ]]] ) : string<\/code><\/pre>\n<h3>PHP <code>wordwrap()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>str<\/code> \u2014 The input string. <\/p>\n<\/li>\n<li>\n<p><code>width<\/code> \u2014 The number of characters at which the string will be wrapped. <\/p>\n<\/li>\n<li>\n<p><code>break<\/code> \u2014 The line is broken using the optional break parameter. <\/p>\n<\/li>\n<li>\n<p><code>cut<\/code> \u2014 If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart. (See second example). When FALSE the function does not split the word even if the width is smaller than the word width. <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>wordwrap()<\/code> Return Value<\/h3>\n<p>The PHP <code>wordwrap()<\/code> function returns the given string wrapped at the specified length.<\/p>\n<h3>PHP <code>wordwrap()<\/code> Working Examples<\/h3>\n<h4>1. wordwrap() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = \"The quick brown fox jumped over the lazy dog.\";\n$newtext = wordwrap($text, 20, \"&lt;br \/&gt;\\n\");\necho $newtext;\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">The quick brown fox&lt;br \/&gt;\njumped over the lazy&lt;br \/&gt;\ndog.<\/code><\/pre>\n<h4>2. wordwrap() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = \"A very long woooooooooooord.\";\n$newtext = wordwrap($text, 8, \"\\n\", true);\necho \"$newtext\\n\";\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">A very\nlong\nwooooooo\nooooord.<\/code><\/pre>\n<h4>3. wordwrap() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n$text = \"A very long woooooooooooooooooord. and something\";\n$newtext = wordwrap($text, 8, \"\\n\", false);\necho \"$newtext\\n\";\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">A very\nlong\nwoooooooooooooooooord.\nand\nsomething<\/code><\/pre>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: ju1ius<\/p>\n<pre><code class=\"lang-php\">Another solution to utf-8 safe wordwrap, unsing regular expressions.\nPretty good performance and works in linear time.\n&lt;?php\nfunction utf8_wordwrap($string, $width=75, $break=\"\\n\", $cut=false)\n{\n  if($cut) {\n    \/\/ Match anything 1 to $width chars long followed by whitespace or EOS,\n    \/\/ otherwise match anything $width chars long\n    $search = '\/(.{1,'.$width.'})(?:\\s|$)|(.{'.$width.'})\/uS';\n    $replace = '$1$2'.$break;\n  } else {\n    \/\/ Anchor the beginning of the pattern with a lookahead\n    \/\/ to avoid crazy backtracking when words are longer than $width\n    $pattern = '\/(?=\\s)(.{1,'.$width.'})(?:\\s|$)\/uS';\n    $replace = '$1'.$break;\n  }\n  return preg_replace($search, $replace, $string);\n}\n?&gt;\nOf course don't forget to use preg_quote on the $width and $break parameters if they come from untrusted input.<\/code><\/pre>\n<p>Contributed By: Dave Lozier &#8211; dave<\/p>\n<pre><code class=\"lang-php\">If you'd like to break long strings of text but avoid breaking html you may find this useful. It seems to be working for me, hope it works for you. Enjoy. :) \n \n&lt;?php \n    function textWrap($text) { \n        $new_text = ''; \n        $text_1 = explode('&gt;',$text); \n        $sizeof = sizeof($text_1); \n        for ($i=0; $i&lt;$sizeof; ++$i) { \n            $text_2 = explode('&lt;',$text_1[$i]); \n            if (!empty($text_2[0])) { \n                $new_text .= preg_replace('#([^\\n\\r .]{25})#i', '\\\\1  ', $text_2[0]); \n            } \n            if (!empty($text_2[1])) { \n                $new_text .= '&lt;' . $text_2[1] . '&gt;';    \n            } \n        } \n        return $new_text; \n    } \n?&gt;<\/code><\/pre>\n<p><script type=\"text\/javascript\" src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js\"><\/script><br \/>\n<script type=\"text\/javascript\" src=\"https:\/\/tutorialio.com\/wp-content\/themes\/sidenavigation\/script.js\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>addcslashes() \u2014 Quote string with slashes in a C style addslashes() \u2014 Quote string with slashes bin2hex() \u2014 Convert binary data into hexadecimal representation chop() \u2014 Alias of rtrim chr() \u2014 Generate a single-byte string from a number chunk_split() \u2014 Split a string into smaller chunks convert_cyr_string() \u2014 Convert from one Cyrillic character set to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[5,17],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-reference","tag-php","tag-strings"],"_links":{"self":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":0,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"wp:attachment":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}