PHP - Translating Characters with strtr()

Introduction

You can replace certain characters in a string with certain other characters.

Demo

<?php
$myString = "Here's a little string";

// Displays "Here-s+a+little+string"
echo strtr( $myString, "'", "+-" ) . " \n ";
?>//from w w  w.j a v a  2s . c  om

strtr()  is especially useful if you need to translate a string from one character set to another.

Result

Related Topic