★ wanayoo — archive 1999 http://www.php.net/manual/fr/function.strtr.phpNouvelle recherche | Portail wanayoo
PHP Thursday, March 29, 2001  
downloads | documentation | faq | support | reporting bugs | links 

search for in the  

lookup:
Manuel PHPManuel PHP
ChaînesChaînes
 AddCSlashesAddCSlashes
 AddSlashesAddSlashes
 bin2hexbin2hex
 ChopChop
 ChrChr
 chunk_splitchunk_split
 convert_cyr_stringconvert_cyr_string
 count_charscount_chars
 crc32crc32
 cryptcrypt
 echoecho
 explodeexplode
 get_html_translation_tableget_html_translation_table
 get_meta_tagsget_meta_tags
 hebrevhebrev
 hebrevchebrevc
 htmlentitieshtmlentities
 htmlspecialcharshtmlspecialchars
 implodeimplode
 joinjoin
 levenshteinlevenshtein
 localeconvlocaleconv
 ltrimltrim
 md5md5
 MetaphoneMetaphone
 nl2brnl2br
 OrdOrd
 parse_strparse_str
 printprint
 printfprintf
 quoted_printable_decodequoted_printable_decode
 QuoteMetaQuoteMeta
 rtrimrtrim
 sscanfsscanf
 setlocalesetlocale
 similar_textsimilar_text
 soundexsoundex
 sprintfsprintf
 strncasecmpstrncasecmp
 strcasecmpstrcasecmp
 strchrstrchr
 strcmpstrcmp
 strcollstrcoll
 strcspnstrcspn
 strip_tagsstrip_tags
 StripCSlashesStripCSlashes
 StripSlashesStripSlashes
 stristrstristr
 strlenstrlen
 strnatcmpstrnatcmp
 strnatcasecmpstrnatcasecmp
 strncmpstrncmp
 str_padstr_pad
 strposstrpos
 strrchrstrrchr
 str_repeatstr_repeat
 strrevstrrev
 strrposstrrpos
 strspnstrspn
 strstrstrstr
 strtokstrtok
 strtolowerstrtolower
 strtoupperstrtoupper
 str_replacestr_replace
 strtrstrtr
 substrsubstr
 substr_countsubstr_count
 substr_replacesubstr_replace
 trimtrim
 ucfirstucfirst
 ucwordsucwords
 wordwrapwordwrap

previousstr_replace
substrnext

Last updated: Wed, 21 Mar 2001
view this page in English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Spanish | Plain HTML

strtr

(PHP 3, PHP 4 )

strtr --  Remplace toutes les occurrences d'un caractère par un autre.

Description

string strtr (string str, string from, string to)

strtr() travaille sur str, remplacant chaque occurence de chaque caractère de la chaîne from correspondant à la chaîne to et retourne le résultat.

Si from et to sont de longueur différentes, les caractères en trop sont ignorés.

Exemple 1. Exemple avec strtr()


<?php
$addr = strtr($addr, "AAÖ", "aao");
?>
      

strtr() peut aussi être appelée avec deux arguments. Dans ce cas, elle se comporte différemment : from doit être un tableau associatif contenant des paires de chaînes, qui seront remplacées dans la chaîne source. strtr() recherchera toujours la chaîne la plus longue, et la remplacera en premier. Elle ne remplacera jamais une portion de chaîne qu'elle à déjà remplacé.

Exemples:


<?php
$trans = array("bonjour" => "salut", "salut" => "bonjour");
echo strtr("bonjour à tous, j'ai dit salut", $trans)."\n";
?>
      

Cete exemple affichera : "salut à tous, j'ai dit bonjour",

Note : Travailler avec deux arguments a été ajouté dans PHP 4.0.

Voir aussi ereg_replace().

User Contributed Notes: strtr
clambert@gamespy.com
17-Aug-2000 05:40
This function is case sensitive. Therefore, strtr("abc","ABC","xyz") would return abc.

Perhaps we'll see an stritr in the future, but otherwise you'll have to:
1) call it with only two paramaters and use the array feature (PHP 4)
2) add on the extra characters to the end of both $to and $from
3) use eregi_replace

herve@milk.fr
11-Oct-2000 07:21
strtr() is useful when trying to convert a string from PHP to Javascript (as JS doesn't allow linebreaks in string declarations) :

<script language="Javascript">
&lt;?php
print("var js_string = \"%s\";",strtr($php_string,"\n\r\t\0"," ");
?>

bvr@xs4all.nl
12-Jan-2001 06:38
for translating html entities to text use this:

$trans = array_flip(get_html_translation_table(HTML_ENTITIES));
$trans["&amp;"] = "&";
$str = strtr($str,$trans);

note that when you reverse the translation table with array_flip()
some characters aren't translated correctly (like &amp; for example).

to check the translation table use:

print_r($trans);


bvr.

previousstr_replace
substrnext

Last updated: Wed, 21 Mar 2001
add note | about notes

show source | credits | stats | mirror sites:  

Copyright © 1998-2001 The PHP Group
All rights reserved.
This mirror generously provided by: chek.com
Last updated: Thu Mar 29 14:40:03 2001 EST