我记得以前这样做过,但找不到代码.我使用str_replace来替换这样的一个字符:str_replace(':', ' ', $string);但我想替换所有以下字符\/:*?"<>|,而不是为每个字符执行str_replace.
str.format在PHP中是否有相当于Python 的东西?
在Python中:
"my {} {} cat".format("red", "fat")
Run Code Online (Sandbox Code Playgroud)
所有我认为我可以用PHP本身做的就是命名条目并使用str_replace:
str_replace(array('{attr1}', '{attr2}'), array('red', 'fat'), 'my {attr1} {attr2} cat')
Run Code Online (Sandbox Code Playgroud)
还有其他PHP的原生替代品吗?
我需要使用str_replace替换多个值.
这是我的PHP代码替换.
$date = str_replace(
array('y', 'm', 'd', 'h', 'i', 's'),
array('Year', 'Month', 'Days', 'Hours', 'Munites', 'Seconds'),
$key
);
Run Code Online (Sandbox Code Playgroud)
当我通过m在$key它返回象输出.
MontHours
Run Code Online (Sandbox Code Playgroud)
当我通过h在$key它返回的输出.
HourSeconds
Run Code Online (Sandbox Code Playgroud)
它返回这个值我想要的Month唯一.
直到第13个字符被击中为止.一旦str_ireplace在cyper数组中命中"a",str_ireplace就会停止工作.
数组的大小是否有限制?请记住,如果键入"abgf",我会得到"nots",但如果我输入"abgrf",当我得到"注释"时,我会得到"notrs".我的大脑无法弄明白.
$_cypher = array("n","o","p","q","r","s","t","u","v","w","x","y","z","a","b","c","d","e","f","g","h","i","j","k","l","m");
$_needle = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$_decryptedText = str_ireplace($_cypher, $_needle, $_text);
echo $_decryptedText;
Run Code Online (Sandbox Code Playgroud)
救命?