strtr

  • Translating certain characters in a string in Ruby works pretty similar in Ruby to that in PHP. Ruby uses the String#tr method to perform translations. The Ruby method does not accept an array as an argument like it does in PHP.

    PHP

    $result = strtr("cat", "abc", "zyx");
    var_export($result);
    // => 'xzt'

    Ruby

    p "cat".tr("abc", "zyx")
    # => "xzt"

    see also

strtoupper substr

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.