PHP str_replace 是否有超过 13 个字符的限制?
直到第 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;
帮助?
This works up until the 13th character is hit. Once the str_ireplace hits "a" in the cyper array, the str_ireplace stops working.
Is there a limit to how big the array can be? Keep in mind if type "abgf" i get "nots", but if I type "abgrf" when I should get "notes" I get "notrs". Racked my brain cant figure it out.
$_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;
Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
strtr
文档< /sup>:演示
它将替换每一对,在已替换的字符串上一对接着一对。因此,如果您替换了再次替换的字符,则可能会发生这种情况:
您的 e 替换在您的 r 替换之后进行。
Use
strtr
Docs:Demo
It will replace each pair, one pair after the other on the already replaced string. So if you replace a character that you replace again, this can happen:
Your e-replacement comes after your r-replacement.
查看 str_replace 的文档。即以下行:
所以它按照所说的那样工作。它只是进行循环替换(n -> a,然后 a -> n)。
Take a peak at the docs for str_replace. Namely the following line:
So it's working as told. It's just doing a circular replacement (n -> a, then a -> n).
使用 str_rot13
Use str_rot13
虽然它看起来是一个直接的 rot13,但如果不是,另一种选择是使用 strtr()。您提供一个字符串和一个替换对数组,然后返回结果翻译。
although it appears to be a straight rot13, if it is not, another option is to use strtr(). You provide a string and an array of replacement pairs and get the resulting translation back.