strtr() function in PHP


The strstr() is used to translate a character or replace substring.

Syntax

strstr(str, from, to)
or
strstr(str, arr)

Parameters

  • str − The string to translate

  • from − The characters to change. A required parameter if array is not used.

  • to − The characters to change into. A required parameter if array is not used.

  • arr − Array containing what to change from as key, and what to change to as value

Return

The strstr() function returns the translated string.

Example

The following is an example −

Live Demo

<?php
   $mystr = "kom lan" ; 
   $str1 = "koml"; 
   $str2 = "tomh";
   echo strtr($mystr, $str1, $str2);
?>

Output

tom han

Updated on: 30-Jul-2019

37 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements