Ceaser cipher?
PHP Code:
$str = "Random string";
$chars = str_split($str);
$char_shift = 1;
for($i=0; $i<count($chars); $i++) {
$chars[$i] = $chars[$i] + $char_shift;
}
$new_string = implode($chars);
echo $new_string;
My PHP isn't great so bare with me..
I'm trying to loop through a string and increment each character depending on an int stored in a variable.
However, instead of printing the char to screen I'd like to replace the original character with the incremented one. Is there a simple way of doing this?PHP Code:
$str = "Random string";
$chars = str_split($str, 1);
foreach($chars as $char)
{
$char++;
echo $char;
}
Thanks in advance.
Ceaser cipher?
PHP Code:
$str = "Random string";
$chars = str_split($str);
$char_shift = 1;
for($i=0; $i<count($chars); $i++) {
$chars[$i] = $chars[$i] + $char_shift;
}
$new_string = implode($chars);
echo $new_string;
All web designers hate the internet. If I spend all day making/updating/looking at websites, why the hell would I want to deal with it outside of work?