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

📄 function.strtr.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Translate certain characters</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="function.strtoupper.html">strtoupper</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.substr-compare.html">substr_compare</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.strtr" class="refentry"> <div class="refnamediv">  <h1 class="refname">strtr</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">strtr</span> &mdash; <span class="dc-title">Translate certain characters</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">string</span> <span class="methodname"><b><b>strtr</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$from</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$to</tt></span>   )</div>  <div class="methodsynopsis dc-description">   <span class="type">string</span> <span class="methodname"><b><b>strtr</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str</tt></span>   , <span class="methodparam"><span class="type">array</span> <tt class="parameter">$replace_pairs</tt></span>   )</div>  <p class="para rdfs-comment">   This function returns a copy of <i><tt class="parameter">str</tt></i>,   translating all occurrences of each character in   <i><tt class="parameter">from</tt></i> to the corresponding character in   <i><tt class="parameter">to</tt></i>.  </p>  <p class="para">   If <i><tt class="parameter">from</tt></i> and <i><tt class="parameter">to</tt></i> are   different lengths, the extra characters in the longer of the two   are ignored.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">str</tt></i></span>     <dd>      <p class="para">       The <a href="language.types.string.html" class="type string">string</a> being translated.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">from</tt></i></span>     <dd>      <p class="para">       The <a href="language.types.string.html" class="type string">string</a> being translated to <i><tt class="parameter">to</tt></i>.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">to</tt></i></span>     <dd>      <p class="para">       The <a href="language.types.string.html" class="type string">string</a> replacing <i><tt class="parameter">from</tt></i>.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">replace_pairs</tt></i></span>     <dd>      <p class="para">       The <i><tt class="parameter">replace_pairs</tt></i> parameter may be used as a substitute for        <i><tt class="parameter">to</tt></i> and <i><tt class="parameter">from</tt></i> in which case it&#039;s an       <a href="language.types.array.html" class="type array">array</a> in the form <i>array(&#039;from&#039; =&gt; &#039;to&#039;, ...)</i>.       </p>     </dd>    </dt>   </dl>  </p> </div>  <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   This function returns a copy of <i><tt class="parameter">str</tt></i>,   translating all occurrences of each character in   <i><tt class="parameter">from</tt></i> to the corresponding character in   <i><tt class="parameter">to</tt></i>.  </p> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.0.0</td>       <td colspan="1" rowspan="1" align="left">        The optional <i><tt class="parameter">to</tt></i> and <i><tt class="parameter">from</tt></i>        parameters were added.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>strtr()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$addr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strtr</span><span style="color: #007700">(</span><span style="color: #0000BB">$addr</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"盲氓枚"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"aao"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   <b>strtr()</b> may be called with only two   arguments. If called with two arguments it behaves in a new way:   <i><tt class="parameter">from</tt></i> then has to be an array that contains   string -&gt; string pairs that will be replaced in the source   string. <b>strtr()</b> will always look for the   longest possible match first and will *NOT* try to replace stuff   that it has already worked on.  </p>  <div class="example">   <p><b>Example #2 <b>strtr()</b> example with two arguments</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$trans&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"hello"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"hi"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"hi"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strtr</span><span style="color: #007700">(</span><span style="color: #DD0000">"hi&nbsp;all,&nbsp;I&nbsp;said&nbsp;hello"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$trans</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>    <div class="example-contents"><p>The above example will output:</p></div>    <div class="example-contents"><pre><div class="cdata"><pre>hello all, I said hi</pre></div>    </pre></div>  </div> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.ereg-replace.html" class="function" rel="rdfs-seeAlso">ereg_replace()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strtoupper.html">strtoupper</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.substr-compare.html">substr_compare</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

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