Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to manipulate each character in a php string
How to manipulate each character in a php string
2.php.net/manual/zh/function.chr.php

2.php.net/manual/zh/function.ord.php

It is better to use these two functions. php is not as good at handling characters as C language.

Put this sentence: $ resultstring. = $ str[$ I]+ 1;

Change to: $ resultstring. = chr(ord($ str[$ I])+ 1);

Echo? Decoding ('ABCDE'); //output bcdef

Echo? Decoding ('XYZ'); //output yz{

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

Function? Decoding ($ str) (

$resultString? =? "";

For ($ me? =? 0; $i? & lt? strlen($ str); $i++){

$resultString。 = chr(ord($ str[$ I])+ 1); //Convert characters to ascii code+1 and then back.

}

Return? $ resultString

}

Echo? Decoding ('ABCDE');

Echo? & lt/br & gt; ';

Echo? Decoding ('XYZ');

& gt