PHP strtr() Funzione
❮ Riferimento alla stringa PHP
Esempio
Sostituisci i caratteri "ia" nella stringa con "eo":
<?php
echo strtr("Hilla Warld","ia","eo");
?>
Definizione e utilizzo
La funzione strtr() traduce determinati caratteri in una stringa.
Nota: se i parametri from e to hanno una lunghezza diversa, entrambi verranno formattati alla lunghezza più breve.
Sintassi
strtr(string,from,to)
o
strtr(string,array)
Valori dei parametri
Parameter | Description |
---|---|
string | Required. Specifies the string to translate |
from | Required (unless array is used). Specifies what characters to change |
to | Required (unless array is used). Specifies what characters to change into |
array | Required (unless to and from is used). An array containing what to change from as key, and what to change to as value |
Dettagli tecnici
Valore di ritorno: | Restituisce la stringa tradotta. Se il parametro array contiene una chiave che è una stringa vuota (""), restituirà FALSE. |
---|---|
Versione PHP: | 4+ |
Altri esempi
Esempio
Sostituisci la stringa "Hello world" con "Hi earth":
<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
❮ Riferimento alla stringa PHP