⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.types.string.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Strings</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.types.float.html">Floating point numbers</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.types.array.html">Arrays</a></div> <div class="up"><a href="language.types.html">Types</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.types.string" class="sect1"> <h2 class="title">Strings</h2> <p class="para">  A <a href="language.types.string.html" class="type string">string</a> is series of characters. Before PHP 6, a character is  the same as a byte. That is, there are exactly 256 different characters  possible. This also implies that PHP has no native support of Unicode. See  <a href="function.utf8-encode.html" class="function">utf8_encode()</a> and <a href="function.utf8-decode.html" class="function">utf8_decode()</a> for some  basic Unicode functionality. </p> <blockquote><p><b class="note">Note</b>:   <span class="simpara">   It is no problem for a <a href="language.types.string.html" class="type string">string</a> to become very large. PHP imposes   no boundary on the size of a <a href="language.types.string.html" class="type string">string</a>; the only limit is the   available memory of the computer on which PHP is running.  </span> </p></blockquote> <div id="language.types.string.syntax" class="sect2">  <h3 class="title">Syntax</h3>  <p class="para">   A <a href="language.types.string.html" class="type string">string</a> literal can be specified in four different ways:  </p>  <ul class="itemizedlist">   <li class="listitem">    <span class="simpara">     <a href="language.types.string.html#language.types.string.syntax.single" class="link">single quoted</a>    </span>   </li>   <li class="listitem">    <span class="simpara">     <a href="language.types.string.html#language.types.string.syntax.double" class="link">double quoted</a>    </span>   </li>   <li class="listitem">    <span class="simpara">     <a href="language.types.string.html#language.types.string.syntax.heredoc" class="link">heredoc syntax</a>    </span>   </li>   <li class="listitem">    <span class="simpara">     <a href="language.types.string.html#language.types.string.syntax.nowdoc" class="link">nowdoc syntax</a>     (since PHP 5.3.0)    </span>   </li>  </ul>  <div id="language.types.string.syntax.single" class="sect3">   <h4 class="title">Single quoted</h4>   <p class="para">    The simplest way to specify a <a href="language.types.string.html" class="type string">string</a> is to enclose it in single    quotes (the character <i>&#039;</i>).   </p>   <p class="para">    To specify a literal single quote, escape it with a backslash    (<i>\</i>). To specify a literal backslash before a single    quote, or at the end of the <a href="language.types.string.html" class="type string">string</a>, double it    (<i>\\</i>). Note that attempting to escape any other character    will print the backslash too.   </p>   <blockquote><p><b class="note">Note</b>:     <span class="simpara">     Unlike the two other syntaxes,     <a href="language.variables.html" class="link">variables</a> and escape sequences     for special characters will <em class="emphasis">not</em> be expanded when they     occur in single quoted <a href="language.types.string.html" class="type string">string</a>s.    </span>   </p></blockquote>   <div class="informalexample">    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'this&nbsp;is&nbsp;a&nbsp;simple&nbsp;string'</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #DD0000">'You&nbsp;can&nbsp;also&nbsp;have&nbsp;embedded&nbsp;newlines&nbsp;in&nbsp;<br />strings&nbsp;this&nbsp;way&nbsp;as&nbsp;it&nbsp;is<br />okay&nbsp;to&nbsp;do'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs:&nbsp;Arnold&nbsp;once&nbsp;said:&nbsp;"I'll&nbsp;be&nbsp;back"<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Arnold&nbsp;once&nbsp;said:&nbsp;"I\'ll&nbsp;be&nbsp;back"'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs:&nbsp;You&nbsp;deleted&nbsp;C:\*.*?<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'You&nbsp;deleted&nbsp;C:\\*.*?'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs:&nbsp;You&nbsp;deleted&nbsp;C:\*.*?<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'You&nbsp;deleted&nbsp;C:\*.*?'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs:&nbsp;This&nbsp;will&nbsp;not&nbsp;expand:&nbsp;\n&nbsp;a&nbsp;newline<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'This&nbsp;will&nbsp;not&nbsp;expand:&nbsp;\n&nbsp;a&nbsp;newline'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs:&nbsp;Variables&nbsp;do&nbsp;not&nbsp;$expand&nbsp;$either<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Variables&nbsp;do&nbsp;not&nbsp;$expand&nbsp;$either'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </div>  <div id="language.types.string.syntax.double" class="sect3">   <h4 class="title">Double quoted</h4>   <p class="para">    If the <a href="language.types.string.html" class="type string">string</a> is enclosed in double-quotes (&quot;), PHP will    interpret more escape sequences for special characters:   </p>   <table border="5">    <caption><b>Escaped characters</b></caption>    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Sequence</th>       <th colspan="1">Meaning</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\n</i></td>       <td colspan="1" rowspan="1" align="left">linefeed (LF or 0x0A (10) in ASCII)</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\r</i></td>       <td colspan="1" rowspan="1" align="left">carriage return (CR or 0x0D (13) in ASCII)</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\t</i></td>       <td colspan="1" rowspan="1" align="left">horizontal tab (HT or 0x09 (9) in ASCII)</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\v</i></td>       <td colspan="1" rowspan="1" align="left">vertical tab (VT or 0x0B (11) in ASCII) (since PHP 5.2.5)</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\f</i></td>       <td colspan="1" rowspan="1" align="left">form feed (FF or 0x0C (12) in ASCII) (since PHP 5.2.5)</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\\</i></td>       <td colspan="1" rowspan="1" align="left">backslash</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\$</i></td>       <td colspan="1" rowspan="1" align="left">dollar sign</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\&quot;</i></td>       <td colspan="1" rowspan="1" align="left">double-quote</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\[0-7]{1,3}</i></td>       <td colspan="1" rowspan="1" align="left">        the sequence of characters matching the regular expression is a        character in octal notation       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left"><i>\x[0-9A-Fa-f]{1,2}</i></td>       <td colspan="1" rowspan="1" align="left">        the sequence of characters matching the regular expression is a        character in hexadecimal notation

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -