<span id="Label3"></p><p><p>String functions in the PHP language are also a relatively understandable knowledge. Today we summed up nearly 12 kinds of PHP string functions, I hope that the need for friends to help, increase the reader friend's PHP knowledge base.</p></p><p><p></p></p><p><p><strong>1. Find character position function</strong></p></p><p><p></p></p><p><p>Strpos ($str, search,[int]): Find the first position of search in $str starting with int;</p></p><p><p>Stripos ($str, search,[int]): function returns the position of the first occurrence of a string in another string. This function is not sensitive to case</p></p><p><p>Strrpos ($str, search,[int]): Find the last occurrence of search in $str from int</p></p><p><p></p></p><p><p><strong>2. Extracting sub-character functions (double-byte)</strong></p></p><p><p>Submit ($str, int Start[,int length]): extracts [length string] from strat position in $str.</p></p><p><p>Strstr ($str 1, $str 2): searches for $str2 from $STR1 (the first Position) and intercepts the end string from it, or False if None.</p></p><p><p>The Stristr () function is the same as strstr, but is not case Sensitive.</p></p><p><p>STRRCHR () prompt returned from the last word searched; use: fetch the file name in the path</p></p><p><p><strong>3. PHP string function to replace string</strong></p></p><p><p>Str_replace (search,replace, $str): Find search from $STR Replace with replace</p></p><p><p>Str_irreplace (search,replace, $str):</p></p><p><p>STRTR ($str, search,replace): Replace in this function cannot be "";</p></p><p><p>Substr_replace ($Str, $rep, $start [, length]) $str The original string, $rep replace the new</p></p><p><p>The string, $start start position, $length The length of the replacement, which is optional</p></p><p><p><strong>4. Character length</strong></p></p><p><p>int strlen ($str)</p></p><p><p><strong>5. Compare character functions</strong></p></p><p><p>int strcmp ($str 1, $str 2): $str 1>=< $str 2 are positive 1,0,-1 (string Comparison)</p></p><p><p>strcasecmp () ditto (no Case)</p></p><p><p>STRNATCMP ("4", "14") Compare strings by natural sort</p></p><p><p>strnatcasecmp () ibid. (case sensitive)</p></p><p><p><strong>6. PHP String functions for splitting into groups</strong></p></p><p><p>Str_split ($str, len): splits the $STR by Len length returns the array</p></p><p><p>Split (search, $str [, int]): splits the $str by the search character returns the array int is split several times, the back will not be split</p></p><p><p>Expload (search, $str [, int])</p></p><p><p><strong>7, Remove the Space:</strong></p></p><p><p>ltrim, rtrim, Trim</p></p><p><p><strong>8, Add the Space function</strong></p></p><p><p>Chunk_split ($str, 2); Add a space by 2 characters to the $str character;</p></p><p><p><strong>9, chr, Ord--returns The specified character or ASCII</strong></p></p><p><p><strong>10. HTML Code related functions</strong></p></p><p><p>NL2BR (): make convert to <br>.</p></p><p><p>Strip_tags ($str [, ¹<p>¹]): remove HTML and PHP tags</p></p><p><p>In $str all HTML and PHP code will be removed, and the optional parameters for HTML and PHP code will be preserved</p></p><p><p>The code that is written for the optional parameter.</p></p><p><p>Such as: Echo strip_tags ($text, ¹<br><p>¹);</p></p><p><p></p></p><p><p>Htmlspecialchars ($str [, parameters]): page Normal output HTML code parameter is the conversion mode</p></p><p><p><strong>11. Character-case-conversion PHP String functions</strong></p></p><p><p>Strtolower ($str) string converted to lowercase</p></p><p><p>Strtoupper ($str) string converted to uppercase</p></p><p><p>Ucfirst ($str) Converts the first character of a function to uppercase</p></p><p><p>Ucwords ($str) Converts the first letter of each word to uppercase</p></p><p><p><strong>12. database-related PHP String functions</strong></p></p><p><p>Addslashes ($str): makes the single quotation mark (¹), double quotation mark ("), backslash () and NUL in str</p></p><p><p>The string is converted to ¹, ", \.</p></p><p><p>MAGIC_QUOTES_GPC = on automatically escapes the contents of the Get post cookie</p></p><p><p>GET_MAGIC_QUOTES_GPC () detects if MAGIC_QUOTES_GPC is turned on</p></p><p><p>Stripslashes () to remove backslashes from a string</p></p><p><p></p></p><p><p>Article from: http://developer.51cto.com/art/200911/164634.htm</p></p><p><p>php--string Function Classification Summary</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service