gpt4 book ai didi

php - PHP str_replace 是否有超过 13 个字符的限制?

转载 作者:行者123 更新时间:2023-12-04 21:49:35 26 4
gpt4 key购买 nike

这一直有效到第 13 个字符被击中。一旦 str_ireplace 命中 cyper 数组中的“a”,str_ireplace 就会停止工作。

数组的大小有限制吗?请记住,如果键入“abgf”,我会得到“nots”,但是如果我在应该得到“notes”的时候键入“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;

帮忙吗?

最佳答案

使用strtrDocs :

$_text = 'abgrf';

$translate = array_combine($_cypher, $_needle);

$_decryptedText = strtr($_text, $translate);

echo $_decryptedText; # notes

Demo


But, was there something I was doing wrong?

它将替换每一对,在已经替换的字符串上一对接一个地替换。因此,如果您再次替换一个字符,可能会发生这种情况:

    r -> e   e -> r
abgrf -> notes -> notrs

您的 e-replacement 在您的 r-replacement 之后。

关于php - PHP str_replace 是否有超过 13 个字符的限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7771658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com