Current Location: Home> Function Categories> strtr

strtr

Translate characters or replace substrings - convert specified characters
Name:strtr
Category:String
Programming Language:php
One-line Description:Converts specific characters in a string.

Example

Example 1

Replace the character "ia" in the string with "eo":

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strtr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hilla Warld"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"ia"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"eo"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Example 2

Replace the string "Hello world" with "Hi earth":

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token variable">$arr</span> <span class="token operator">=</span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"Hi"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"world"</span> <span class="token operator">=></span> <span class="token string double-quoted-string">"earth"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token function">strtr</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world"</span> <span class="token punctuation">,</span> <span class="token variable">$arr</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Try it yourself

Similar Functions
  • Alias of strstr strchr

    strchr

    Aliasofstrstr
  • Calculate the md5 hash value of a given file md5_file

    md5_file

    Calculatethemd5hashv
  • Convert hexadecimal string to binary string hex2bin

    hex2bin

    Converthexadecimalst
  • Find any one of a set of characters in a string - Return a substring that starts with the found character strpbrk

    strpbrk

    Findanyoneofasetofch
  • Inversely escape an escaped string stripslashes

    stripslashes

    Inverselyescapeanesc
  • Output one or more strings echo

    echo

    Outputoneormorestrin
  • Generate single-byte strings from numbers chr

    chr

    Generatesingle-bytes
  • One-way string hash crypt

    crypt

    One-waystringhash
Popular Articles