PHP strsrt()函数与示例
PHPstrsrt()方法
strsrt()函数是PHP中的字符串函数,用于替换字符串中的字符。在此功能中,我们可以提供多个要替换的字符,以新的多个替换字符集。(例如:如果我们想将“a”替换为“x”,将“b”替换为“y”,那么我们可以传递“ab”替换为“xy”))
语法:
strstr(string, old, new);
这里,
string是主要字符串,我们必须在其中替换某些字符。
old是要替换的字符集。
new是要替换的字符集。
例子:
Input:
str = "这是一个游戏。";
old = "ia"
new = "eo"
Output:
Thes es o Gome.
Input:
str = "这是一个游戏。";
old = " ."
new = "_#"
Output:
This_is_a_Game#PHP代码:
<?php $str = "这是一个游戏。"; //replacing "i" with "e" and "a" with "0" echo (strtr($str,"ia","eo") . "\n"); $str = "这是一个游戏。"; //replacing space with "_" and dot (.) with "#" echo (strtr($str," .","_#") . "\n"); ?>
输出结果
Thes es o Gome. This_is_a_Game#
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿