Does PHP str_replace have a limit of more than 13 characters?

This is triggered until the 13th character is reached. As soon as str_ireplace gets into "cyper", "str" ​​stops working.

Is there a limit to how big the array is? Keep in mind if the type is "abgf" I get "nots", but if I type "abgrf" when I get "notes", I get "notrs". Stacked my brain can not 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; 

reference

+2
php compiler-errors str-replace
Oct 14 2018-11-18T00:
source share
4 answers

Use strtr Docs :

 $_text = 'abgrf'; $translate = array_combine($_cypher, $_needle); $_decryptedText = strtr($_text, $translate); echo $_decryptedText; # notes 

Demo




But was there something I was doing wrong?

It will replace each pair, one pair after another on an already replaced line. Therefore, if you replace a character that you replace again, this may happen:

  r -> ee -> r abgrf -> notes -> notrs 

Your electronic replacement comes after your r-replacement.

+5
Oct 14 '11 at 18:08
source share

Take the rush in the docs for str_replace . Namely, the following line:

Since str_replace () replaces from left to right, it can replace a previously inserted value when executing multiple notes. See also examples in this document.

So it works as it is said. It just does a circular swap (n → a, then a → n).

+2
Oct 14 '11 at 18:13
source share
+1
Oct. 14 2018-11-18T00:
source share

although it seems direct rot13, if it is not, another option is to use strtr () . You provide a string and an array of replacement pairs and return the resulting translation.

0
Oct 14 '11 at 18:09
source share



All Articles