PHP str_replace有超过13个字符的限制吗? [英] Does PHP str_replace have a greater than 13 character limit?
问题描述
这直到第13个字符被击中。一旦str_ireplace命中了cyper数组中的a,str_ireplace就会停止工作。
This works up until the 13th character is hit. Once the str_ireplace hits "a" in the cyper array, the str_ireplace stops working.
数组有多大?记住,如果输入abgf我得到nots,但如果我输入abgrf,当我应该得到笔记我得到notrs。
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;
帮助?
推荐答案
使用 strtr
:
$_text = 'abgrf';
$translate = array_combine($_cypher, $_needle);
$_decryptedText = strtr($_text, $translate);
echo $_decryptedText; # notes
是错误的?
But, was there something I was doing wrong?
它将替换每对,一对接一对替换已经替换的字符串。因此,如果您替换了您要重新替换的字符,可能会发生这种情况:
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:
r -> e e -> r
abgrf -> notes -> notrs
您的电子换货是您的换货后。
Your e-replacement comes after your r-replacement.
这篇关于PHP str_replace有超过13个字符的限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!