<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >String 字符串处理函数</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="stream_wrapper_unregister" HREF="function.stream-wrapper-unregister.html"><LINK REL="NEXT" TITLE="addcslashes" HREF="function.addcslashes.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.stream-wrapper-unregister.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.addcslashes.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.strings" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CLXI. String 字符串处理函数</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN224362" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="strings.intro" >简介</A ></H1 ><P > 本类函数用来对字符串进行各种操作。对字符串的一些其它专门操作,可以参考手册的正则表达式部分和 <A HREF="ref.url.html" >URL 操作</A >部分。 </P ><P > 如果想要了解字符串的相关内容,特别是有关单引号,双引号等的处理部分,可以参考手册中<A HREF="language.types.html" >类型</A >部分中的<A HREF="language.types.string.html" >字符串</A >条目。 </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="strings.requirements" >需求</A ></H1 ><P >要编译本扩展模块无需外部库文件。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="strings.installation" >安装</A ></H1 ><P >本扩展模块作为 PHP 内核的一部分,无需安装即可使用。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="string.constants" >预定义常量</A ></H1 ><P >以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。</P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CRYPT_SALT_LENGTH</B ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CRYPT_STD_DES</B ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CRYPT_EXT_DES</B ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CRYPT_MD5</B ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CRYPT_BLOWFISH</B ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >HTML_SPECIALCHARS</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >HTML_ENTITIES</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >ENT_COMPAT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >ENT_QUOTES</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >ENT_NOQUOTES</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CHAR_MAX</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_CTYPE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_NUMERIC</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_TIME</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_COLLATE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_MONETARY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_ALL</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >LC_MESSAGES</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >STR_PAD_LEFT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >STR_PAD_RIGHT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >STR_PAD_BOTH</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="strings.seealso" >参见</A ></H1 ><P > 如果想更深入的了解有关字符串高级操作的相关内容,请参阅手册的 <A HREF="ref.regex.html" >POSIX 扩展正则表达式函数</A >和 <A HREF="ref.pcre.html" >Perl 兼容正则表达式函数</A >部分。 </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="function.addcslashes.html" >addcslashes</A > -- 以 C 语言风格使用反斜线转义字符串中的字符</DT ><DT ><A HREF="function.addslashes.html" >addslashes</A > -- 使用反斜线引用字符串</DT ><DT ><A HREF="function.bin2hex.html" >bin2hex</A > -- 将二进制数据转换成十六进制表示</DT ><DT ><A HREF="function.chop.html" >chop</A > -- <A HREF="function.rtrim.html" ><B CLASS="function" >rtrim()</B ></A > 的别名</DT ><DT ><A HREF="function.chr.html" >chr</A > -- 返回指定的字符</DT ><DT ><A HREF="function.chunk-split.html" >chunk_split</A > -- 将字符串分割成小块</DT ><DT ><A HREF="function.convert-cyr-string.html" >convert_cyr_string</A > -- 将字符由一种 Cyrillic 字符转换成另一种</DT ><DT ><A HREF="function.convert-uudecode.html" >convert_uudecode</A > -- Decode a uuencoded string </DT ><DT ><A HREF="function.convert-uuencode.html" >convert_uuencode</A > -- Uuencode a string </DT ><DT ><A HREF="function.count-chars.html" >count_chars</A > -- 返回字符串所用字符的信息</DT ><DT ><A HREF="function.crc32.html" >crc32</A > -- 计算一个字符串的 crc32 多项式</DT ><DT ><A HREF="function.crypt.html" >crypt</A > -- One-way string encryption (hashing)</DT ><DT ><A HREF="function.echo.html" >echo</A > -- Output one or more strings</DT ><DT ><A HREF="function.explode.html" >explode</A > -- 使用一个字符串分割另一个字符串</DT ><DT ><A HREF="function.fprintf.html" >fprintf</A > -- Write a formatted string to a stream</DT ><DT ><A HREF="function.get-html-translation-table.html" >get_html_translation_table</A > -- Returns the translation table used by <A HREF="function.htmlspecialchars.html" ><B CLASS="function" >htmlspecialchars()</B ></A > and <A HREF="function.htmlentities.html" ><B CLASS="function" >htmlentities()</B ></A > </DT ><DT ><A HREF="function.hebrev.html" >hebrev</A > -- Convert logical Hebrew text to visual text </DT ><DT ><A HREF="function.hebrevc.html" >hebrevc</A > -- Convert logical Hebrew text to visual text with newline conversion </DT ><DT ><A HREF="function.html-entity-decode.html" >html_entity_decode</A > -- Convert all HTML entities to their applicable characters </DT ><DT ><A HREF="function.htmlentities.html" >htmlentities</A > -- Convert all applicable characters to HTML entities </DT ><DT ><A HREF="function.htmlspecialchars-decode.html" >htmlspecialchars_decode</A > -- Convert special HTML entities back to characters </DT ><DT ><A HREF="function.htmlspecialchars.html" >htmlspecialchars</A > -- Convert special characters to HTML entities </DT ><DT ><A HREF="function.implode.html" >implode</A > -- Join array elements with a string</DT ><DT ><A HREF="function.join.html" >join</A > -- 别名 <A HREF="function.implode.html" ><B CLASS="function" >implode()</B ></A ></DT ><DT ><A HREF="function.levenshtein.html" >levenshtein</A > -- Calculate Levenshtein distance between two strings </DT ><DT ><A HREF="function.localeconv.html" >localeconv</A > -- Get numeric formatting information</DT ><DT ><A HREF="function.ltrim.html" >ltrim</A > -- Strip whitespace (or other characters) from the beginning of a string </DT ><DT ><A HREF="function.md5-file.html" >md5_file</A > -- Calculates the md5 hash of a given file</DT ><DT ><A HREF="function.md5.html" >md5</A > -- Calculate the md5 hash of a string</DT ><DT ><A HREF="function.metaphone.html" >metaphone</A > -- Calculate the metaphone key of a string</DT ><DT ><A HREF="function.money-format.html" >money_format</A > -- Formats a number as a currency string</DT ><DT ><A HREF="function.nl-langinfo.html" >nl_langinfo</A > -- Query language and locale information </DT ><DT ><A HREF="function.nl2br.html" >nl2br</A > -- Inserts HTML line breaks before all newlines in a string </DT ><DT ><A HREF="function.number-format.html" >number_format</A > -- Format a number with grouped thousands</DT ><DT ><A HREF="function.ord.html" >ord</A > -- Return ASCII value of character</DT ><DT ><A HREF="function.parse-str.html" >parse_str</A > -- Parses the string into variables</DT ><DT ><A HREF="function.print.html" >print</A > -- Output a string</DT ><DT ><A HREF="function.printf.html" >printf</A > -- Output a formatted string</DT ><DT ><A HREF="function.quoted-printable-decode.html" >quoted_printable_decode</A > -- Convert a quoted-printable string to an 8 bit string </DT ><DT ><A HREF="function.quotemeta.html" >quotemeta</A > -- Quote meta characters</DT ><DT ><A HREF="function.rtrim.html" >rtrim</A > -- Strip whitespace (or other characters) from the end of a string </DT ><DT ><A HREF="function.setlocale.html" >setlocale</A > -- Set locale information</DT ><DT ><A HREF="function.sha1-file.html" >sha1_file</A > -- Calculate the sha1 hash of a file</DT ><DT ><A HREF="function.sha1.html" >sha1</A > -- Calculate the sha1 hash of a string</DT ><DT ><A HREF="function.similar-text.html" >similar_text</A > -- Calculate the similarity between two strings </DT ><DT ><A HREF="function.soundex.html" >soundex</A > -- Calculate the soundex key of a string</DT ><DT ><A HREF="function.sprintf.html" >sprintf</A > -- Return a formatted string</DT ><DT ><A HREF="function.sscanf.html" >sscanf</A > -- Parses input from a string according to a format </DT ><DT ><A HREF="function.str-getcsv.html" >str_getcsv</A > -- Parse a CSV string into an array </DT ><DT ><A HREF="function.str-ireplace.html" >str_ireplace</A > -- Case-insensitive version of <A HREF="function.str-replace.html" ><B CLASS="function" >str_replace()</B ></A >. </DT ><DT ><A HREF="function.str-pad.html" >str_pad</A > -- Pad a string to a certain length with another string </DT ><DT ><A HREF="function.str-repeat.html" >str_repeat</A > -- Repeat a string</DT ><DT ><A HREF="function.str-replace.html" >str_replace</A > -- Replace all occurrences of the search string with the replacement string </DT ><DT ><A HREF="function.str-rot13.html" >str_rot13</A > -- Perform the rot13 transform on a string</DT ><DT ><A HREF="function.str-shuffle.html" >str_shuffle</A > -- Randomly shuffles a string</DT ><DT ><A HREF="function.str-split.html" >str_split</A > -- Convert a string to an array </DT ><DT ><A HREF="function.str-word-count.html" >str_word_count</A > -- Return information about words used in a string </DT ><DT ><A HREF="function.strcasecmp.html" >strcasecmp</A > -- Binary safe case-insensitive string comparison </DT ><DT ><A HREF="function.strchr.html" >strchr</A > -- 别名 <A HREF="function.strstr.html" ><B CLASS="function" >strstr()</B ></A ></DT ><DT ><A HREF="function.strcmp.html" >strcmp</A > -- Binary safe string comparison</DT ><DT ><A HREF="function.strcoll.html" >strcoll</A > -- Locale based string comparison</DT ><DT ><A HREF="function.strcspn.html" >strcspn</A > -- Find length of initial segment not matching mask </DT ><DT ><A HREF="function.strip-tags.html" >strip_tags</A > -- Strip HTML and PHP tags from a string</DT ><DT ><A HREF="function.stripcslashes.html" >stripcslashes</A > -- Un-quote string quoted with <A HREF="function.addcslashes.html" ><B CLASS="function" >addcslashes()</B ></A > </DT ><DT ><A HREF="function.stripos.html" >stripos</A > -- Find position of first occurrence of a case-insensitive string </DT ><DT ><A HREF="function.stripslashes.html" >stripslashes</A > -- Un-quote string quoted with <A HREF="function.addslashes.html" ><B CLASS="function" >addslashes()</B ></A > </DT ><DT ><A HREF="function.stristr.html" >stristr</A > -- Case-insensitive <A HREF="function.strstr.html" ><B CLASS="function" >strstr()</B ></A > </DT ><DT ><A HREF="function.strlen.html" >strlen</A > -- Get string length</DT ><DT ><A HREF="function.strnatcasecmp.html" >strnatcasecmp</A > -- Case insensitive string comparisons using a "natural order" algorithm </DT ><DT ><A HREF="function.strnatcmp.html" >strnatcmp</A > -- String comparisons using a "natural order" algorithm </DT ><DT ><A HREF="function.strncasecmp.html" >strncasecmp</A > -- Binary safe case-insensitive string comparison of the first n characters </DT ><DT ><A HREF="function.strncmp.html" >strncmp</A > -- Binary safe string comparison of the first n characters </DT ><DT ><A HREF="function.strpbrk.html" >strpbrk</A > -- Search a string for any of a set of characters </DT ><DT ><A HREF="function.strpos.html" >strpos</A > -- Find position of first occurrence of a string </DT ><DT ><A HREF="function.strrchr.html" >strrchr</A > -- Find the last occurrence of a character in a string </DT ><DT ><A HREF="function.strrev.html" >strrev</A > -- Reverse a string</DT ><DT ><A HREF="function.strripos.html" >strripos</A > -- Find position of last occurrence of a case-insensitive string in a string </DT ><DT ><A HREF="function.strrpos.html" >strrpos</A > -- Find position of last occurrence of a char in a string </DT ><DT ><A HREF="function.strspn.html" >strspn</A > -- Find length of initial segment matching mask </DT ><DT ><A HREF="function.strstr.html" >strstr</A > -- Find first occurrence of a string</DT ><DT ><A HREF="function.strtok.html" >strtok</A > -- Tokenize string</DT ><DT ><A HREF="function.strtolower.html" >strtolower</A > -- Make a string lowercase</DT ><DT ><A HREF="function.strtoupper.html" >strtoupper</A > -- Make a string uppercase</DT ><DT ><A HREF="function.strtr.html" >strtr</A > -- Translate certain characters</DT ><DT ><A HREF="function.substr-compare.html" >substr_compare</A > -- Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characters </DT ><DT ><A HREF="function.substr-count.html" >substr_count</A > -- Count the number of substring occurrences</DT ><DT ><A HREF="function.substr-replace.html" >substr_replace</A > -- Replace text within a portion of a string</DT ><DT ><A HREF="function.substr.html" >substr</A > -- Return part of a string</DT ><DT ><A HREF="function.trim.html" >trim</A > -- Strip whitespace (or other characters) from the beginning and end of a string</DT ><DT ><A HREF="function.ucfirst.html" >ucfirst</A > -- Make a string's first character uppercase</DT ><DT ><A HREF="function.ucwords.html" >ucwords</A > -- Uppercase the first character of each word in a string </DT ><DT ><A HREF="function.vfprintf.html" >vfprintf</A > -- Write a formatted string to a stream</DT ><DT ><A HREF="function.vprintf.html" >vprintf</A > -- Output a formatted string</DT ><DT ><A HREF="function.vsprintf.html" >vsprintf</A > -- Return a formatted string</DT ><DT ><A HREF="function.wordwrap.html" >wordwrap</A > -- Wraps a string to a given number of characters using a string break character </DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.stream-wrapper-unregister.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.addcslashes.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >stream_wrapper_unregister</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >addcslashes</TD ></TR ></TABLE ></DIV ></BODY ></HTML >