I am trying to use preg_replace
to change numbers to letters, but only numbers wrapped in ""
and not more than 7 characters in the substring.
Sample input string:
"3"sca"""co"1"str"0"ctor""r"3"t"0"r"1""locat"5"o"133""0"27""754a49b393c2a0"33"b97"332"cb7"3"c3c07"2""co"1"str"0"ctor""r"3"t"0"
The desired effect is for every qualifying 2
to become d
and every qualifying 3
to become e
.
These are examples of correct replacements:
-
"3"
becomese
-
"23"
becomesde
-
"33"
becomesee
-
"32"
becomesde
-
"333223"
becomeseeedde
My coding attempt:
$string = preg_replace("/\"322\"+/", "edd", $string);
$string = preg_replace("/\"233\"+/", "dee", $string);
$string = preg_replace("/\"32\"+/", "ed", $string);
$string = preg_replace("/\"23\"+/", "de", $string);
$string = preg_replace("/\"33\"+/", "e", $string);
$string = preg_replace("/\"333\"+/", "e", $string);
$string = preg_replace("/\"3\"+/", "e", $string);
$string = preg_replace("/\"3\"+/", "e", $string);
$string = preg_replace("/\"3\"+/", "e", $string);
$string = preg_replace("/\"3\"+/", "e", $string);
$string = preg_replace("/\"3\"+/", "e", $string);
How can I make all qualifying replacements with one preg_replace call?