python函数示例
PHP strsrt()函数 (PHP strsrt() Function)
strsrt() function is a string function in PHP, it is used to replaces characters in the string. In this function, we can provide multiple characters to be replaced with the set of new multiple characters to replace with. (Example: if we want to replace "a" with "x" and "b" with "y" – then we can pass "ab" to replace with "xy").
strsrt()函数是PHP中的字符串函数,用于替换字符串中的字符。 在此功能中,我们可以提供要替换为新字符集的多个字符。 (例如:如果我们想将“ a”替换为“ x”,而将“ b”替换为“ y” ,则可以传递“ ab”替换为“ xy” ))
Syntax:
句法:
strstr(string, old, new);
Here,
这里,
string is the main string, in which we have to replace certain characters.
string是主要字符串,在其中我们必须替换某些字符。
old is the set of characters to be replaced.
old是要替换的字符集。
new is the set of characters to replace.
new是要替换的字符集。
Examples:
例子:
Input:
str = "This is a Game.";
old = "ia"
new = "eo"
Output:
Thes es o Gome.
Input:
str = "This is a Game.";
old = " ."
new = "_#"
Output:
This_is_a_Game#
PHP code:
PHP代码:
<?php
$str = "This is a Game.";
//replacing "i" with "e" and "a" with "0"
echo (strtr($str,"ia","eo") . "\n");
$str = "This is a Game.";
//replacing space with "_" and dot (.) with "#"
echo (strtr($str," .","_#") . "\n");
?>
Output
输出量
Thes es o Gome.
This_is_a_Game#
翻译自: https://www.includehelp.com/php/strstr-function-with-example.aspx
python函数示例