De la bonne utilisation de strtr()

Essayez un jour de taper ceci :

<?php
$lockMessage
= "This container is currently being edited by %account";
$lockMessage = strtr($lockMessage, '%account', 'Anonymous');
?>

Que pensez vous obtenir? Personnellement, j'ai été assez surpris, voici le résultat:

This nyounioer is nmrreouly beiog ediued by Annnymou

Oui, et bien la prochaine fois, je relis la doc avant d'utiliser une telle fonction en faisant confiance à mon intuition, et je tape :

<?php
$lockMessage
= "This container is currently being edited by %account";
$lockMessage = strtr($lockMessage, array('%account' => 'Anonymous'));
?>

Conclusion : RTFM!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
F
3
m
h
x
4
Enter the code without spaces and pay attention to upper/lower case.